docmd.openform problem

ajb_1976

Registered User.
Local time
Today, 23:13
Joined
Feb 25, 2005
Messages
34
Hello,

I have an issue whereby i want to be able to present the user with a text box in which they can either enter a client id (numeric) or a client name (string) which will then form the filter on an underlying query for a form.

I have entered the following code on the <afterupdate> trigger of the text box and when the user selects a client id it works fine and opens the desired form showing the filtered result of the client id entered. But when the user enters a string value an "enter parameter" pop up appears - if the string is re-entered in this box the form will open with the desired filter in place. What do i need to do in order to have the string value work seamlessly as the numeric value does.

Dim strText As String

If IsNumeric(ctlSearch) Then
strText = "ClientID = " & ctlSearch
Else
strText = "Surname = " & ctlSearch
End If

DoCmd.OpenForm "frmEdit_Clients", , , strText

Thanks,
Alan
 
When handling text you need to wrap single quotes around the string, such as

strText = "Surname = '" & ctlSearch & "'"

With dates you use #'s

numbers do not need anything.

David
 
David,

thanks for the prompt reply, now working perfectly

Thanks again,

Alan
 

Users who are viewing this thread

Back
Top Bottom