OpenForm with stCriteria

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
 
S

Stefan Hoffmann

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 <--
 
S

Stefan Hoffmann

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 <--
 
D

Douglas J Steele

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 & "'")
 

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