Open form with where clause

eacollie

Registered User.
Local time
Today, 01:05
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
 
looks to me like you have an extra comma so your where clause is being applied to the datamode parameter
 
Thank you so much!
 
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!
 
Think I figured it out...using DLookup instead of an SQL. Thank you
 
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

Back
Top Bottom