By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,681 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,681 IT Pros & Developers. It's quick & easy.

Search command button causing Error 2501

P: 3
I am brand new to VBA - so if this is a brain-donor question...sorry!!

I have a search button on my switchboard with two fields next to it - Status and Technician.

I can search for both fields and it brings up my form.
I can search for just Status and it brings up my form.

But if I attempt to search by just Technician (stEmpID) it brings back a Run-Time Error 2501 The OpenForm was canceled.

Can someone see something I don't here?

Dim stEmpID As String
Dim iStatusID As Long
Dim stDocName As String
Dim stLinkCriteria As String
Dim stMsg As String

stEmpID = Nz(Me.cmbSupportTechforFindATicket, "")
iStatusID = Nz(Me.cmbTicketStatusforFindATicket, 0)

If ((stEmpID = "") And (iStatusID = 0)) Then
stMsg = "You must select either a Technician or a Status to use this search."
MsgBox stMsg
Exit Sub

stDocName = "frmTicketSearchBYStatusOrTech"

If Not ((stEmpID = "") Or (iStatusID = 0)) Then
stLinkCriteria = "((TicketStatusID =" & iStatusID & ") AND (EmployeeID=""" & stEmpID & """))"""

ElseIf iStatusID = 0 Then
stLinkCriteria = "EmployeeID = " & stEmpID

ElseIf stEmpID = "" Then
stLinkCriteria = "TicketStatusID = " & iStatusID

End If

DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

End Sub
Jul 2 '07 #1
Share this Question
Share on Google+
1 Reply

P: 3
un, nevermind. realized I was treated it as a number instead of string. Got it. :)
Jul 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.