using Like statement in where condition for docmd.openform

hoda64

Registered User.
Local time
Yesterday, 22:47
Joined
Jun 18, 2008
Messages
30
Hello,

I want to open a form based on two conditions: a date and a facility name

The problem is that the data I have is not consistent when it comes to the facility name part. For example, if I wanted to search "apple" the data might have "apple" written as "apple1" or "apple2". Therefore it is not enough to just have name = apple because I will miss apple1 and apple2. To get around this, I have been using the "like" statement. So if it is like *apple* then apple1 and apple2 will be included.

I have been trying to write the docmd.openform condition to include the ability to use the "like" statement, but have been unsuccessful. Can someone tell me if that is possible, and if so, what the syntax is? This "where" condition seems to be pretty tricky when it comes to quotations...

This is my latest attempt, I get a type mismatch error:

Code:
DoCmd.OpenForm "InputLER", acNormal, , "[Event Date] = Forms!InputCOMPSIS![Date of Event] And [Facility] Like " * " & Forms!InputCOMPSIS!Name & " * ""

Thanks in advance, I really appreciate it!
 
Several problems. Try this:

DoCmd.OpenForm "InputLER", acNormal, , "[Event Date] = #" & Forms!InputCOMPSIS![Date of Event] & "# And [Facility] Like '*" & Forms!InputCOMPSIS!Name & "*'"
 
Thanks!! :D That worked, I am going to try to figure out what you did. I'll be back with questions if I cant figure it out. Thanks again!
 
No problem. Hints: concatenation and delimiters.
 
Several problems. Try this:

DoCmd.OpenForm "InputLER", acNormal, , "[Event Date] = #" & Forms!InputCOMPSIS![Date of Event] & "# And [Facility] Like '*" & Forms!InputCOMPSIS!Name & "*'"
Just over 10 years later and this thread carried the day, thanks Paul!
 
Happy to help NG! I'll PM you our schedule, but flying in 10/7.
 

Users who are viewing this thread

Back
Top Bottom