DoCmd.OpenForm WHERE problem

JonAccess

Registered User.
Local time
Today, 15:25
Joined
Sep 15, 2011
Messages
35
I do not know what is wrong with my code and thought I needed a different set of eyes. When I run this code, it opens up the form, but filters to show a blank record instead of the matching record. I'm guessing, for some reason, what I'm searching for doesn't match anything in my records. Any ideas?

Code:
Private Sub CmdSearch_Click()
 
Dim strDoc As String
Dim strWhere As String
 
strDoc = "frm_Main_Cust_Data"
strWhere = "forms!frm_Main_Cust_Data![Customer_Name] like ""*" & Me!
[cust_#] & "*"""
 
DoCmd.OpenForm strDoc, acNormal, , strWhere
 
End Sub

I've also tried to no avail:
Code:
strWhere = "forms!frm_Main_Cust_Data![Customer_Name] like[COLOR=red] [B]'[/B][/COLOR]*" & Me!
[cust_#] & "*[B][COLOR=red]'[/COLOR][/B]"

[Customer_Name] is a Text field

Thanks in advance
 
BTW, My strWhere variable is supposed to be on one line.
Code:
strWhere = "forms!frm_Main_Cust_Data![Customer_Name] like ""*" & Me![cust_#] & "*"""
 
Here you go:
Code:
strWhere = "[Customer_Name] LIKE '*" & Me![cust_#] & "*'"
 
If I take out the whole reference to "Customer_Name" then Access prompts me for a parameter for field "Customer_Name"

Wonder what causes that?
 
What's it's saying is [Customer Name] appears twice in the form's record source. You will need to qualify the field with its table name as well, so:
Code:
strWhere = "[COLOR=Red]TableName.[/COLOR][Customer_Name] LIKE '*" & Me![cust_#] & "*'"
 
I checked my forms record source and saw that it was based on some funky SQL statement that I didn't know where it came from. I just based the form off of the table and our original code works! Thank you for tipping me off to the record source. Wonder why that funky record source was in there? Scares me to not know what the was.
 

Users who are viewing this thread

Back
Top Bottom