In the code below, the sequence of events is as follows;
Load event runs through all commands and set's focus to cboFamily.
cboFamily gotfocus event does it's stuff.
cboFamily_afterupdate runs and set's focus to cboGenus.
cboGenus goes through to cboGenus.dropdown.
If I'm stepping through, the dropdown list appears. If not, cboGenus.itemdata(0) is selected.
Stepping through, the sequence of events is;
cboFamily_afterupdate end sub.
cboFamily_gotfocus end if then end sub.
At this point the error message appears.
Clicking debug shows the error line as "cboFamily.setfocus" in the load event.
txtfamily and txtGenus are initially not visible and sit directly behind cboFamily and cboGenus respectively.
Load event runs through all commands and set's focus to cboFamily.
cboFamily gotfocus event does it's stuff.
cboFamily_afterupdate runs and set's focus to cboGenus.
cboGenus goes through to cboGenus.dropdown.
If I'm stepping through, the dropdown list appears. If not, cboGenus.itemdata(0) is selected.
Stepping through, the sequence of events is;
cboFamily_afterupdate end sub.
cboFamily_gotfocus end if then end sub.
At this point the error message appears.
Clicking debug shows the error line as "cboFamily.setfocus" in the load event.
txtfamily and txtGenus are initially not visible and sit directly behind cboFamily and cboGenus respectively.
Code:
Option Compare Database
Option Explicit
Private Sub cboFamily_AfterUpdate()
Me.txtFamily = Me.cboFamily
Me.cboGenus.Requery
Me.cboGenus.setFocus
End Sub
Private Sub cboFamily_GotFocus()
Do
If Nz(Me.cboFamily.ItemData(0), "") = "" Then
Forms("Discrepancies").txtgetFamily = Left(Forms("Discrepancies").txtgetFamily, Len(Forms("Discrepancies").txtgetFamily) - 1)
Me.cboFamily.Requery
End If
Loop While Nz(Me.cboFamily.ItemData(0), "") = ""
Me.cboFamily = Me.cboFamily.ItemData(0)
If Nz(Me.cboFamily.ItemData(1), "") = "" Then
cboFamily_AfterUpdate
Else
Me.cboFamily.Dropdown
End If
End Sub
Private Sub cboGenus_AfterUpdate()
Me.btnShow.Caption = "Double click the ""Copy Genus"" data" & vbCrLf & _
"or the ""Copy Family"" data." & vbCrLf & _
"Right click to copy the correct spelling." & vbCrLf & _
"You can then paste onto the main form."
Me.lblGenus.Caption = "Copy Genus."
Me.txtGenus = Me.cboGenus
Me.lblFamily.Caption = "Copy Family."
Me.txtFamily.Visible = True
Me.txtFamily.setFocus
Me.cboFamily.Visible = False
Me.txtGenus.Visible = True
Me.txtGenus.setFocus
Me.cboGenus.Visible = False
End Sub
Private Sub cboGenus_GotFocus()
Me.cboGenus = Me.cboGenus.ItemData(0)
If Nz(Me.cboGenus.ItemData(1), "") > "" Then
Me.cboGenus.Dropdown
Else
cboGenus_AfterUpdate
End If
End Sub
Private Sub CloseBtn_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Form_Load()
Me.Visible = True
Me.lblFamily.Caption = "Family."
Me.lblGenus.Caption = "Genus."
Me.txtFamily.Visible = False
Me.cboFamily.Visible = True
Me.txtGenus.Visible = False
Me.cboGenus.Visible = True
Me.btnShow.Caption = "Use the information on this form" & vbCrLf & _
"to correct the spelling of" & vbCrLf & _
"Family and Genus data on the main form."
Me.cboFamily.Requery
Me.cboFamily.setFocus
End Sub
Last edited: