Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / January 2007

Tip: Looking for answers? Try searching our database.

OpenArgs data type mismatch in criteria expression

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobby - 31 Jan 2007 12:56 GMT
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
Allen Browne - 31 Jan 2007 13:20 GMT
Try:
   If IsNumeric(Me.OpenArgs) Then
       link = Val(Me.OpenArgs)
   End If

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi
>
[quoted text clipped - 40 lines]
>
> Any help appreciated
Keith Wilby - 31 Jan 2007 13:24 GMT
> Hi
>
[quoted text clipped - 22 lines]
>
>    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
bobby - 31 Jan 2007 14:38 GMT
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

> > Hi
> >
[quoted text clipped - 31 lines]
> HTH - Keith.
> www.keithwilby.com 
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.