I have a form called fSearchforCompany with two unbound fields. After selecting a field from lstQuickSearch (list box) and tabbing to txtSearchBox to enter data, the correct form should open with the text from txtSearchBox entered into the designated field. But, first the code should check for null, and if Null, open the correct form.
The problems are the code is not doing anything on Null and when there is data it is not selecting the data.
The two fields are:
1. lstQuickSearch
ControlSource is empty
Row Source = 1;"Company ID";2;"Company Name";3;"Date
of Event";4;"Event Type"
Row Type = Value List
2. txtSearchBox
Control Source is empty
After Update Event code is listed below:
Private Sub txtSearchBox_AfterUpdate()
On Error GoTo ErrorHandler
Select Case Me.lstQuickSearch.Value
Case 1:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("[frmListforCompanyID")
DoCmd.GoToControl ("cboSearchBox")
Else
DoCmd.OpenForm ("frmListforCompanyID")
DoCmd.GoToControl ("cboSearchBox")
Forms!frmListforCompanyID!cboSearchBox.ControlSource =
txtSearchBox
End If
Case 2:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("frmListforCompanyName")
DoCmd.GoToControl ("cboSearchBox")
Else
DoCmd.OpenForm ("frmListforCompanyName")
DoCmd.GoToControl ("cboSearchBox")
Forms!frmListforCompanyName!cboSearchBox.ControlSource =
txtSearchBox
End If
Case 2:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("fdlgEventDetail")
DoCmd.GoToControl ("txtEventDate")
Else
DoCmd.OpenForm ("fdlgEventDetail")
DoCmd.GoToControl ("txtEventDate")
Forms!fdlgEventDetail!txtEventDate.ControlSource =
txtSearchBox
End If
Case Else
MsgBox "Invalid selection", vbExclamation
Exit Sub
End Select
CleanUpAndExit:
Exit Sub
ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume CleanUpAndExit
End Sub
Thanks for any help!
The problems are the code is not doing anything on Null and when there is data it is not selecting the data.
The two fields are:
1. lstQuickSearch
ControlSource is empty
Row Source = 1;"Company ID";2;"Company Name";3;"Date
of Event";4;"Event Type"
Row Type = Value List
2. txtSearchBox
Control Source is empty
After Update Event code is listed below:
Private Sub txtSearchBox_AfterUpdate()
On Error GoTo ErrorHandler
Select Case Me.lstQuickSearch.Value
Case 1:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("[frmListforCompanyID")
DoCmd.GoToControl ("cboSearchBox")
Else
DoCmd.OpenForm ("frmListforCompanyID")
DoCmd.GoToControl ("cboSearchBox")
Forms!frmListforCompanyID!cboSearchBox.ControlSource =
txtSearchBox
End If
Case 2:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("frmListforCompanyName")
DoCmd.GoToControl ("cboSearchBox")
Else
DoCmd.OpenForm ("frmListforCompanyName")
DoCmd.GoToControl ("cboSearchBox")
Forms!frmListforCompanyName!cboSearchBox.ControlSource =
txtSearchBox
End If
Case 2:
If IsNull(txtSearchBox) Then
DoCmd.OpenForm ("fdlgEventDetail")
DoCmd.GoToControl ("txtEventDate")
Else
DoCmd.OpenForm ("fdlgEventDetail")
DoCmd.GoToControl ("txtEventDate")
Forms!fdlgEventDetail!txtEventDate.ControlSource =
txtSearchBox
End If
Case Else
MsgBox "Invalid selection", vbExclamation
Exit Sub
End Select
CleanUpAndExit:
Exit Sub
ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , "Error")
Resume CleanUpAndExit
End Sub
Thanks for any help!