2 opening arguments

R

Ripper

I am attempting to open a form from a continuous form. I can get the open
statement to work when I have 1 opening argument, however, when I combine I
get a Runtime Error '13' Type Mismatch. This is the command I am using:

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID And
"[BoxNumber] =" & Me.BoxNumber

TestID and BoxNumber are both number fields.
 
K

Keith Wilby

Ripper said:
I am attempting to open a form from a continuous form. I can get the open
statement to work when I have 1 opening argument, however, when I combine
I
get a Runtime Error '13' Type Mismatch. This is the command I am using:

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID And
"[BoxNumber] =" & Me.BoxNumber

TestID and BoxNumber are both number fields.

Try

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID & " And
[BoxNumber] = " & Me.BoxNumber

If either data type is text then you'll also need quotation marks.

Keith.
www.keithwilby.co.uk
 
M

Marshall Barton

Ripper said:
I am attempting to open a form from a continuous form. I can get the open
statement to work when I have 1 opening argument, however, when I combine I
get a Runtime Error '13' Type Mismatch. This is the command I am using:

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID And
"[BoxNumber] =" & Me.BoxNumber

TestID and BoxNumber are both number fields.


The And needs to ne inside quotes:
... "TestID =" & Me.TestID & " And BoxNumber =" &
Me.BoxNumber
 
R

Ripper

Works Perfect. Why does it have to be in quotes. It doesn't make sense to
include the AND.
--
Thanks As Always
Rip


Keith Wilby said:
Ripper said:
I am attempting to open a form from a continuous form. I can get the open
statement to work when I have 1 opening argument, however, when I combine
I
get a Runtime Error '13' Type Mismatch. This is the command I am using:

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID And
"[BoxNumber] =" & Me.BoxNumber

TestID and BoxNumber are both number fields.

Try

DoCmd.OpenForm "frmNonCountablesEdit", , , "[TestID] =" & Me.TestID & " And
[BoxNumber] = " & Me.BoxNumber

If either data type is text then you'll also need quotation marks.

Keith.
www.keithwilby.co.uk
 
K

Keith Wilby

Ripper said:
Works Perfect. Why does it have to be in quotes. It doesn't make sense
to
include the AND.

Because you're building a SQL string at run-time which will parse to
something like

"[TestID] = 123 And [BoxNumber] = 987"

The ampersand (&) is used to join the literal text parts of the expression
to references to objects on your form.

A more elegant way to code this would be

Dim strSQL as String
strSQL = "[TestID] =" & Me.TestID & " And [BoxNumber] = " & Me.BoxNumber
DoCmd.OpenForm "frmNonCountablesEdit", , , strSQL

You could then put a break point in your code after that line, go to the
immediate window and type

?strSQL

to see what the string actually contains.

HTH - Keith.
www.keithwilby.com.uk
 

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