If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Form Setfocus
I have a Form with 2 date fields. I need to test if one date1 field is older
or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#2
|
|||
|
|||
Form Setfocus
The issue here is that before you can make the comparison, both fields need
to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#3
|
|||
|
|||
Form Setfocus
Hi Dave
Thanks for the reply. I'm happy with testing the 2 dates bit. I am using 1 of the date fields to do the testing, in the After_update event. The only bit of code that fails to work is the Me.Date2.Setfocus. I can Setfocus to any other control on the form but not the Date2 control. I guess I need a another control to do the setfocus bit. regards johnb "Klatuu" wrote: The issue here is that before you can make the comparison, both fields need to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#4
|
|||
|
|||
Form Setfocus
I don't know why you can't set focus to that control. Is it enabled and not
locked? Is it in the Tab Order? Is is a normal bound control or is there something special about it? -- Dave Hargis, Microsoft Access MVP "johnb" wrote: Hi Dave Thanks for the reply. I'm happy with testing the 2 dates bit. I am using 1 of the date fields to do the testing, in the After_update event. The only bit of code that fails to work is the Me.Date2.Setfocus. I can Setfocus to any other control on the form but not the Date2 control. I guess I need a another control to do the setfocus bit. regards johnb "Klatuu" wrote: The issue here is that before you can make the comparison, both fields need to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#5
|
|||
|
|||
Form Setfocus
David,
Properties.Enabled = Yes and locked = No; The Form is bound to a table. The Control in question is a Medium Date field. I've messed about with Setfocus all morning and I can get it to focus on all other controls on the form witout a any problem. It seems that if a control triggers an event then you can not setfocus back to that control that triggered the event. I've compacted etc. and compiled.....but no change! Kind regards johnb "Klatuu" wrote: I don't know why you can't set focus to that control. Is it enabled and not locked? Is it in the Tab Order? Is is a normal bound control or is there something special about it? -- Dave Hargis, Microsoft Access MVP "johnb" wrote: Hi Dave Thanks for the reply. I'm happy with testing the 2 dates bit. I am using 1 of the date fields to do the testing, in the After_update event. The only bit of code that fails to work is the Me.Date2.Setfocus. I can Setfocus to any other control on the form but not the Date2 control. I guess I need a another control to do the setfocus bit. regards johnb "Klatuu" wrote: The issue here is that before you can make the comparison, both fields need to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#6
|
|||
|
|||
Form Setfocus
Try adding this before you set the focus:
Private Sub CheckDates() Dim ctl As Control If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed ctl = Screen.ActiveControl If ctl.Name "Date2" Then Me.Date2.SetFocus End If End If End Sub If Date2 has the focus, it will ignore setting the focus and raising the error; otherwise, it will set the focus to Date2. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: David, Properties.Enabled = Yes and locked = No; The Form is bound to a table. The Control in question is a Medium Date field. I've messed about with Setfocus all morning and I can get it to focus on all other controls on the form witout a any problem. It seems that if a control triggers an event then you can not setfocus back to that control that triggered the event. I've compacted etc. and compiled.....but no change! Kind regards johnb "Klatuu" wrote: I don't know why you can't set focus to that control. Is it enabled and not locked? Is it in the Tab Order? Is is a normal bound control or is there something special about it? -- Dave Hargis, Microsoft Access MVP "johnb" wrote: Hi Dave Thanks for the reply. I'm happy with testing the 2 dates bit. I am using 1 of the date fields to do the testing, in the After_update event. The only bit of code that fails to work is the Me.Date2.Setfocus. I can Setfocus to any other control on the form but not the Date2 control. I guess I need a another control to do the setfocus bit. regards johnb "Klatuu" wrote: The issue here is that before you can make the comparison, both fields need to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
#7
|
|||
|
|||
Form Setfocus
Hi David
I've got to work. Well its crap but its consistent. I've justed added "Me.AnotherControlName.Setfocus" one line above the Me.txtEffectiveDate.Setfocus and it WORKS!!!! I've no idea why. I shall now try your solution. Regards johnb "Klatuu" wrote: Try adding this before you set the focus: Private Sub CheckDates() Dim ctl As Control If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed ctl = Screen.ActiveControl If ctl.Name "Date2" Then Me.Date2.SetFocus End If End If End Sub If Date2 has the focus, it will ignore setting the focus and raising the error; otherwise, it will set the focus to Date2. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: David, Properties.Enabled = Yes and locked = No; The Form is bound to a table. The Control in question is a Medium Date field. I've messed about with Setfocus all morning and I can get it to focus on all other controls on the form witout a any problem. It seems that if a control triggers an event then you can not setfocus back to that control that triggered the event. I've compacted etc. and compiled.....but no change! Kind regards johnb "Klatuu" wrote: I don't know why you can't set focus to that control. Is it enabled and not locked? Is it in the Tab Order? Is is a normal bound control or is there something special about it? -- Dave Hargis, Microsoft Access MVP "johnb" wrote: Hi Dave Thanks for the reply. I'm happy with testing the 2 dates bit. I am using 1 of the date fields to do the testing, in the After_update event. The only bit of code that fails to work is the Me.Date2.Setfocus. I can Setfocus to any other control on the form but not the Date2 control. I guess I need a another control to do the setfocus bit. regards johnb "Klatuu" wrote: The issue here is that before you can make the comparison, both fields need to have a date in them. In addition, you have to decide what to do if one or both date fields are Null. Not knowing the rule for this, I can only offer this as a suggestion. Because you can't be sure which date the user will enter first, I would suggest you create a Sub in your form module to test the dates and call it from the After Update event of both fields: Private Sub CheckDates() If Me.Date2 Me.Date1 Then Me.Date2.BackColor = vbRed Me.Date2.SetFocus End If End Sub A note about setting focus to a form. You can't set the focus to a form if there are any controls on the form capable of accepting the focus. -- Dave Hargis, Microsoft Access MVP "johnb" wrote: I have a Form with 2 date fields. I need to test if one date1 field is older or newer date2. And if date2 is older that date1 then mark date2 Backcolor a different color and set the focus to date2 field. Easy I here you say but not for me! If I enter Me.Form.SetFocus followed by Me.txtEffectiveDate.SetFocus in the After_Update event I get get nowhere. Any Suggession?? TIA johnb |
Thread Tools | |
Display Modes | |
|
|