Problem with Search Button

tjnichols

Registered User.
Local time
Yesterday, 17:05
Joined
Apr 18, 2012
Messages
57
Good evening. I am having problems with my search button. The following is the code attached to the button.


Private Sub Command12_Click()

If (IsNull(cboType)) Or (IsNull(txtCriteria)) Then
MsgBox "Please select search type", vbOKOnly, "please select search type"
ElseIf [cboType] = "FirstName" And [txtCriteria] > "" Then
DoCmd.OpenForm "frmFirstName"
ElseIf [cboType] = "LastName" And [txtCriteria] > "" Then
DoCmd.OpenForm "ConsumersCombined"
ElseIf [cboType] = "ID" And [txtCriteria] > "" Then
DoCmd.OpenForm "ConsumersCombined"
End If


End Sub

I have also uploaded a copy of the database so you can see what that first hand.

Thanks!

Tonya
 

Attachments

Good Evening to you , I am not familar with >"" so assume you mean not empty?
Here is my effort using Access 2003

Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String


If (IsNull(CboTYPE)) Or (IsNull(TxtCriteria)) Then
MsgBox " Please select search type ", vbOKOnly, "please select search type "
End If


If Me.CboTYPE = "FirstName" And Not IsNull(TxtCriteria) Then
DoCmd.OpenForm "FirstName"
ElseIf Me.CboTYPE = "LastName" Or Me.CboTYPE = "ID" And Not IsNull(TxtCriteria) Then
DoCmd.OpenForm "ConsumersCombined"
End If

'

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub
In My example i omitted the frm part of the FirstName Form .
The two Dim statements are not required
 
Last edited:
It looks like the form "frmFirstName" does not exist. That is the first error I get when running this. Is this the issue you are having?
 
I don't know what the problem is - it just does nothing when I click the button. Even with the new code above. Is there a log so I can see the problem? If so, where do I find it?

Thanks!
 
Tonya, is the code you tried the one I posted ? I have tested my code and it works on my PC. As mentioned I missed the frm part of the form name frmFirstName. Have you checked to ensure the fields names are spelt correctly, one quick way is to put a Me.txtCriteria on a spare line to ensure it is recognized , then do the same with the cpoType , you can delete if ok .. Also you could double check that the form names agree to the name on your form list, do you have a frm before the ConsumersCombined form? I am grasping at straws so if you have already done these checks my apologies. I cannot check it with your zip folder as i have not found a way to upload or view attachments .
 
Last edited:
Write code like this may make it easier for you to understand and identify problems.

Private Sub Command12_Click()
If Len(Trim$(Nz(Me.cboType))) = 0 Then
MsgBox "Please select search type.", vbInformation
Me.cboType.SetFocus
Me.cboType.Dropdown
Exit Sub
End If

If Len(Nz(Me.txtCriteria)) = 0 Then
MsgBox "Please type search criteria.", vbInformation
Me.txtCriteria.SetFocus
Exit Sub
End If

Select Case Me.cboType
Case "FirstName"
DoCmd.OpenForm "frmFirstName"
Case "LastName"
DoCmd.OpenForm "ConsumersCombined"
Case "ID"
DoCmd.OpenForm "ConsumersCombined"
Case Else
MsgBox "Unknown search type.", vbCritical
End Select
End Sub
 
Last edited:
Before code is not entirely correct, because it is only open the form, and then do nothing. The right code should look like this:
DoCmd.OpenForm FormName: = "FormName", WhereCondition: = "FirstName = '" & Me.txtCriteria & "'"
(If the open form has record source)

Oh, I do not understand English, I hope you can understand it what I'm saying.
 
Initially - THAT DID THE TRICK!!!! Thank you SOOO MUCH! For not understanding English - you certainly helped me.

Thanks again!
 

Users who are viewing this thread

Back
Top Bottom