OpenArgs data type mismatch in criteria expression

G

Guest

Hi

I'm trying to open an existing record in an amendment form.

The user enters the ref_number in form with a text box and button and this
opens new form passing the ref_number as OpenArgs.

I get an error 'Runtime 3464 data type mismatch in criteria expression.' and
the debugger highlights the line begining Set rst = db.openrecordset ....etc

Here's the code

--------------------------------------------
Private Sub Form_Load()


Dim db As Database, rst As Recordset, link As Integer

link = Me.OpenArgs

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE
(ref_number = '" & link & "')")

rst.MoveFirst

------------------------------------------

When I hover the pointer over & link & it shows the numerical value in
tooltip.
Also ref_numberis the primary key (autonumber).

Currently I have the form working with it being bound to the query but this
means that users are opening the form and changing data on the form without
realising that the changes are immediately reflected in the data. I'm aiming
to to populate the form, allow them to make changes and then only commit to
the change by pressing a save button.

Any help appreciated
 
K

Keith Wilby

bobby said:
Hi

I'm trying to open an existing record in an amendment form.

The user enters the ref_number in form with a text box and button and this
opens new form passing the ref_number as OpenArgs.

I get an error 'Runtime 3464 data type mismatch in criteria expression.'
and
the debugger highlights the line begining Set rst = db.openrecordset
....etc

Here's the code

--------------------------------------------
Private Sub Form_Load()


Dim db As Database, rst As Recordset, link As Integer

link = Me.OpenArgs

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE
(ref_number = '" & link & "')")

rst.MoveFirst

It's a number so remove the single quotation marks (I think one pair of
brackets is redundant too):

Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE [ref_number] =
" & link & ")"

HTH - Keith.
www.keithwilby.com
 
G

Guest

I've amended the offending line to:
Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE [ref_number] =
" & link & "")
and it works now.

Many thanks to you both

Keith Wilby said:
bobby said:
Hi

I'm trying to open an existing record in an amendment form.

The user enters the ref_number in form with a text box and button and this
opens new form passing the ref_number as OpenArgs.

I get an error 'Runtime 3464 data type mismatch in criteria expression.'
and
the debugger highlights the line begining Set rst = db.openrecordset
....etc

Here's the code

--------------------------------------------
Private Sub Form_Load()


Dim db As Database, rst As Recordset, link As Integer

link = Me.OpenArgs

Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE
(ref_number = '" & link & "')")

rst.MoveFirst

It's a number so remove the single quotation marks (I think one pair of
brackets is redundant too):

Set rst = db.OpenRecordset("SELECT * FROM tbl_main_data WHERE [ref_number] =
" & link & ")"

HTH - Keith.
www.keithwilby.com
 

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