Open Args VBA

Neilster

Registered User.
Local time
Today, 13:54
Joined
Jan 19, 2014
Messages
218
Hi Guys

I got this bit of code I've been working on and it's probably a bit silly but I need it to recognise apostrophes.

DoCmd.OpenForm "Frm2ndContact", acNormal, "", "[CompanyName]=" & " '" & (txtCompanyName & "'"), , acNormal
There is a missing operator somewhere maybe someone could shed some light on it.


The form opens fine if say the company is called Daves but not Daves's
 
I think you might have your table set up correctly. You should be using the autonumber Primary key of the table to open a form to a specific comapny, not its name. You do that and this code gets a lot simpler--you don't have to account for special characters when working with numbers.

Do you have an autonumber primary key on the table Frm2ndContact is based on?
 
Yeh just wanted to be a bit fancy that's all, suppose it would work better with the prim key number.
 
Save fancy for the UI. Under the hood, you want efficient.
 
"[CompanyName]=" & " '" & (txtCompanyName & "'"),

That part is written a little wonky. Consider this instead...

"[CompanyName]='" & txtCompanyName & "'",

You had too many ampersands for what you needed, and the parenthesis was totally not needed in this context. I didn't see anything that would have automatically caused any kind of syntax error, but if txtCompanyName contains some type of special character, I suppose something odd would be possible.
 
Doc, he used single quotes to define what CompanyName was equal to. So, if txtCompanyName contained a single quote (Mike's), his criteria argument resolved to this

[CompanyName]='Mike'

And then there was an s off by itself followed by single quote with no partner and things just got unparseable for VBA.
 
plog, I understand, hence my comment on "if txtCompanyName contains some type of special character." The extra syntax he included would not alter that fact.
 

Users who are viewing this thread

Back
Top Bottom