Opening a form based upon two fields...

  • Thread starter Thread starter Lurch
  • Start date Start date
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!
 
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
 
Back
Top