OpenForm with stCriteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to open a form using a numeric variable as the stCriterea.

My Code is:
Dim stDocName As String
Dim stLinkCriteria As String
Dim intTestID as integer

intTestID = 50
stCriteria = "TestID = intTestID"
stDocName = "FormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria

It doesn't work. I'm suspect my problem is the format of the "stCriteria ="
statement, but I'm not sure what it should be.

Any help would be appreciated.

Thanks
 
hi Frank,

Frank said:
I am trying to open a form using a numeric variable as the stCriterea.
Dim stDocName As String
Dim stLinkCriteria As String
Dim intTestID as integer
intTestID = 50
stCriteria = "TestID = intTestID"
stCriteria = "TestID = " & intTestID
stDocName = "FormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria


mfG
--> stefan <--
 
hi,

Stefan said:
stCriteria = "TestID = " & intTestID
stLinkCriteria = "TestID = " & intTestIDIf your original codes is the same as in your posting, then use the
Option Explict in your module headers.


mfG
--> stefan <--
 
Queries don't know anything about variables, so you need to insure that
you've got the value from the variable in your criteria, not the name of the
variable.

Change

stCriteria = "TestID = intTestID"

to

stCriteria = "TestID = " & intTestID

(if TestID were a text field, you'd need to include quotes around that, like
stCriteria = "TestID = '" & intTestID & "'")
 
Back
Top