Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open a form based on ID criteria 2

Status
Not open for further replies.

naoaja

Technical User
Aug 27, 2004
48
US
Please Help.... I am having trouble with what I am sure is the very basics of access. From a command button, I want to open another form based on an ID number. I put
---------------------

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Messages"

stLinkCriteria = "[PetID]=" & "'" & Me![PetID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
--------------------------------------------

If there is a record that matches it, it will open and the Messages form will open with the PetID number in the proper field (PetID). If there is not a record already, it opens the form and it will not put the PetId in the field it should go in. (It is a totally blank record).
If I look at the properties, it has PetID = the number it should be, but I can't get it to populate the PetId field automatically. If there is not a corresponding record there already, I would like to start a new one based on that PetID that is entered automatically.

I hope this makes sense.
I know it is something really basic, but I can't figure it out.

thanks


 
Typed, untested:
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoEvents
If Forms(stDocName).NewRecord Then
Forms(stDocName).Controls("PetID") = Me![PetID]
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
try
stLinkCriteria = "[PetID]= '" & Me![PetID] & "'"

Ian Mayor (UK)
Program Error
There's ALWAYS more than one way to skin a cat!
But only one way to get it RIGHT!
 
PHV -- Thank you so much. This was driving me crazy.

Ian -- thanks for the response, it didn't seem to work though...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top