Opening a form based upon two fields...

L

Lurch

I hope I'm giving enough information with the following code...I keep
getting an Run-time-Error 13 "Type mismatch"...what could I be doing wrong
here. I've tried each one of these separately and they both work if they are
on their own...but when I put them together with the <<And>> I get that
error.

I'm sure this is easy but it has me stumped.

This code is run from a button that is clicked on Form1.

Form2 (continous form) is supposed to open to the records that match both
fields in Form1...all are text in the tables...

DoCmd.OpenForm "frm_Form2", , , "[field1]= forms![form1]![field1]" And
"[field2]= forms![form1]![field2]"

Any help would be GREATLY Appreciated...

Thanks!
 
G

Graham R Seach

Assuming Field1 and Field2 are numeric:
DoCmd.OpenForm "frm_Form2", , , "[field1] = " & Forms!Form1!Field1 & " And
[field2] = " & Forms!Form1!Field2

Assuming Field1 and Field2 are string:
DoCmd.OpenForm "frm_Form2", , , "[field1] = """ & Forms!Form1!Field1 & """
And [field2] = """ & Forms!Form1!Field2 & """"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 

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