Open form with where clause (1 Viewer)

eacollie

Registered User.
Local time
Today, 15:36
Joined
May 14, 2011
Messages
159
I'm getting a type mismatch error when trying to open a form:

Code:
Dim stDocName As String
stDocName = "frmReservations"
DoCmd.OpenForm stDocName, acNormal, , , "[RNOS] = " & 4730
The field [RNOS] is a long integer.

What am I doing wrong?
Thank you
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:36
Joined
Feb 19, 2013
Messages
16,610
looks to me like you have an extra comma so your where clause is being applied to the datamode parameter
 

eacollie

Registered User.
Local time
Today, 15:36
Joined
May 14, 2011
Messages
159
Thank you so much!
 

eacollie

Registered User.
Local time
Today, 15:36
Joined
May 14, 2011
Messages
159
If I'm using a SQL statement and saving the results into a string variable:
Code:
DIM param as string
DIM mySQL as string
Dim stdocname as string

stdocname = "frmReservations"
mySQL = "SELECT....."
param = Val(mySQL)

DoCmd.openform stdocname, , ,"[RNOS] = " & param
Get a 0 value for param. How do I load the correct long integer from the SQL statement into the variable to use to open the form?

Thank you!
 

eacollie

Registered User.
Local time
Today, 15:36
Joined
May 14, 2011
Messages
159
Think I figured it out...using DLookup instead of an SQL. Thank you
 

MarkK

bit cruncher
Local time
Today, 15:36
Joined
Mar 17, 2004
Messages
8,180
Also, there's also no need to do that strDocName thing that the wizards write for you. Just put the name of the form in the open command, or use a constant, like...
Code:
   Const FN as string = "frmReservations"
   DoCmd.OpenForm FN

[COLOR="Green"]   ' or just...[/COLOR]
   DoCmd.OpenForm "frmReservations"

But this wizard code is just trashy....
Code:
Dim stDocName as string
stDocName = "frmReservations"

DoCmd.OpenForm stDocName
IMO
Mark
 

Users who are viewing this thread

Top Bottom