DoCmd.OpenForm from a public function

  • Thread starter Chris O''''Neill
  • Start date
C

Chris O''''Neill

The answer to this is probably so basic I'll want to bang my head against a
wall when it's answered, but right now I'm about ready to throw myself in
front of a bus so a bit of head banging would be preferable. :D

I'm trying to load a form from a public function. The calling form passes
strFormName, strFieldname, and NewData to the function. Here's the code I've
been wrestling with:

strCriteria = "[" & strFieldName & "]" & " = " & NewData
DoCmd.OpenForm strFormName, , , strCriteria, , acDialog

When this code runs, I get an input box with "Enter Parameter Value" as the
title and NewData as the prompt. Of course, what I want is the form to pop
up with the NewData record active.

What am I doing wrong???? Thanks for any help provided!

Regards, Chris
 
S

Stuart McCall

Chris O''''Neill said:
The answer to this is probably so basic I'll want to bang my head against
a
wall when it's answered, but right now I'm about ready to throw myself in
front of a bus so a bit of head banging would be preferable. :D

I'm trying to load a form from a public function. The calling form passes
strFormName, strFieldname, and NewData to the function. Here's the code
I've
been wrestling with:

strCriteria = "[" & strFieldName & "]" & " = " & NewData
DoCmd.OpenForm strFormName, , , strCriteria, , acDialog

When this code runs, I get an input box with "Enter Parameter Value" as
the
title and NewData as the prompt. Of course, what I want is the form to
pop
up with the NewData record active.

What am I doing wrong???? Thanks for any help provided!

Regards, Chris

You're missing quotes around your criteria value (NewData). It should be:

strCriteria = "[" & strFieldName & "]" & " = '" & NewData & "'"
 
C

Chris O''''Neill

Yup! That worked! Thank you, thank you, thank you!!!

I knew the answer was going to be painfully simple. Excuse me while I go
bang my head a couple of times. :D

Regards, Chris

Stuart McCall said:
Chris O''''Neill said:
The answer to this is probably so basic I'll want to bang my head against
a
wall when it's answered, but right now I'm about ready to throw myself in
front of a bus so a bit of head banging would be preferable. :D

I'm trying to load a form from a public function. The calling form passes
strFormName, strFieldname, and NewData to the function. Here's the code
I've
been wrestling with:

strCriteria = "[" & strFieldName & "]" & " = " & NewData
DoCmd.OpenForm strFormName, , , strCriteria, , acDialog

When this code runs, I get an input box with "Enter Parameter Value" as
the
title and NewData as the prompt. Of course, what I want is the form to
pop
up with the NewData record active.

What am I doing wrong???? Thanks for any help provided!

Regards, Chris

You're missing quotes around your criteria value (NewData). It should be:

strCriteria = "[" & strFieldName & "]" & " = '" & NewData & "'"
 
C

Chris O''''Neill

Linq Adams via AccessMonster.com said:
And just so you know the why and wherefore, the syntax you originally had
would have been correct if the Datatype of NewData was Numeric.

Yeah, I figured that out once I saw Stuart's post. As I said, a painfully
obvious solution to something I should've realized before asking the
question. (DOH!!!)
Stuart's syntax works for when the Datatype is Text (which apparently yours
is) and

strCriteria = "[" & strFieldName & "]" & " = #" & NewData & "#"

works if the Datatype of the NewData is Date/Time.

I discovered using "#" for date fields a few days ago, but thanks for the
reminder as I'll be doing a bunch of filtering-on-dates in the next few days.
There's ALWAYS more than one way to skin a cat!

Hmmmm..... once you skin the cat, do you fry it or bake it?!?! :D

Thanks for the additional tip...

Regards, Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top