Hi all, I tried real hard to find the answer.
I have a form (frmWebmail Data Input) where data entry is entered daily and loaded into a table (tblWebmail Data Input). The form has combo boxes, text boxes, a Save, Undo, Search, and Return to Main Menu command buttons.
When I click on the Search button it opens up a second form called frmSearch
(does this make it a sub-form?).
This frmSearch form in turn requests the user to 1) enter text for the search (text box with values entered) and 2) to choose the field to search (based on a table). For example, text to search 'Alex' and field to search 'Agent Name'. When I hit the
Search button here using these criteria, I get the following error code:
"Run-Time error'424': Object required."
When I go to VBA (so not so good at that), the code that is in bold is where the debugger identified the error:
Option Compare Database
Private Sub cboSearchField_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmWebmailDataEntry based on search criteria
Form_frmWebmailDataEntry.RecordSource = "select * from tblWebmail Data Entry where " & GCriteria
Form_frmWebmailDataEntry.Caption = "Webmail Data Entry (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
MsgBox "Results Found."
End If
On Error GoTo Err_cmdSearch_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_cmdSearch_Click:
Exit Sub
Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub
Private Sub Detail_Click()
End Sub
I didn't know how to paste a capture of the VBA, sorry.
So these are the things I would appreciate your help on:
- making the Search command work.
a) if records are located, the frmSeach form closes and the frmWebmail Data Input form opens with all records meeting the criteria!
b) I think I can work out the no records found, but if someone has any suggestions. I figure once the command runs, I would have a pop up stating there were no records found, click on OK, then just back to an empty
frmSearch form. Any other way to think about it?
Sorry for asking for so much.
I've used the Wizard and taken some ideas/coding from some other places, but I still can't make this work.
Thank you all muchly for any help you can provide!