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

Signature
Frank Wagner
fwagner111@aol.com
Stefan Hoffmann - 06 Mar 2006 09:54 GMT
hi Frank,
> 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 <--
Stefan Hoffmann - 06 Mar 2006 10:04 GMT
hi,
>> I am trying to open a form using a numeric variable as the stCriterea.
>> Dim stDocName As String
[quoted text clipped - 3 lines]
>> stCriteria = "TestID = intTestID"
> stCriteria = "TestID = " & intTestID
stLinkCriteria = "TestID = " & intTestID
>> stDocName = "FormName"
>> DoCmd.OpenForm stDocName, , , stLinkCriteria
If your original codes is the same as in your posting, then use the
Option Explict in your module headers.
mfG
--> stefan <--
Douglas J Steele - 06 Mar 2006 13:05 GMT
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 & "'")

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> I am trying to open a form using a numeric variable as the stCriterea.
>
[quoted text clipped - 14 lines]
>
> Thanks
Frank Wagner - 07 Mar 2006 03:20 GMT
Thanks guys. It makes sense and works like a charm.

Signature
Frank Wagner
fwagner111@aol.com
> I am trying to open a form using a numeric variable as the stCriterea.
>
[quoted text clipped - 14 lines]
>
> Thanks