J
juicegully
Hi,
I have a textbox with 2 events: Before Update and Keydown. This textbox is
in a subform and once the user hits "Tab" or "Enter" the focus should be set
to a textbox outside of this subform. However, in my Before Update event I
have a Cancel = True if a certain condition isn't met. Because of this
"Cancel = True" part and the part in my Keydown event where I'm trying to set
the focus elsewhere, I get an error message.
To get around it I was thinking of using the textbox's Exit (or is Lost
Focus better?) event but I'm not sure how to set the focus to outside the
subform if the user hits only either "Tab" or "Enter".
Does anyone have any suggestions?
Here is my code:
Private Sub txtDate_BeforeUpdate(Cancel As Integer)
If IsNull(txtDate) Or txtDate = "" Then
MsgBox "Please enter the date"
Cancel = True
End If
End Sub
Private Sub txtDate_KeyDown(KeyCode As Integer, Shift As Integer)
Dim stForm As String, stSForm As String
stForm = "frmMain"
stSForm = "frmMain-Sub"
If KeyCode = vbKeyReturn Or KeyCode = vbKeyTab Then
KeyCode = 0
DoCmd.GoToControl Forms(stForm).Form(stSForm).Name
Forms(stForm).Form(stSForm).Controls("txtMonth").SetFocus
End If
End Sub
Thanks in advance!
I have a textbox with 2 events: Before Update and Keydown. This textbox is
in a subform and once the user hits "Tab" or "Enter" the focus should be set
to a textbox outside of this subform. However, in my Before Update event I
have a Cancel = True if a certain condition isn't met. Because of this
"Cancel = True" part and the part in my Keydown event where I'm trying to set
the focus elsewhere, I get an error message.
To get around it I was thinking of using the textbox's Exit (or is Lost
Focus better?) event but I'm not sure how to set the focus to outside the
subform if the user hits only either "Tab" or "Enter".
Does anyone have any suggestions?
Here is my code:
Private Sub txtDate_BeforeUpdate(Cancel As Integer)
If IsNull(txtDate) Or txtDate = "" Then
MsgBox "Please enter the date"
Cancel = True
End If
End Sub
Private Sub txtDate_KeyDown(KeyCode As Integer, Shift As Integer)
Dim stForm As String, stSForm As String
stForm = "frmMain"
stSForm = "frmMain-Sub"
If KeyCode = vbKeyReturn Or KeyCode = vbKeyTab Then
KeyCode = 0
DoCmd.GoToControl Forms(stForm).Form(stSForm).Name
Forms(stForm).Form(stSForm).Controls("txtMonth").SetFocus
End If
End Sub
Thanks in advance!