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 IamaSherpa 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 specific field in current form 2

Status
Not open for further replies.

Np02

Technical User
Mar 14, 2003
21
US
Hi, Hope some body can help out:

I have a form call "Template" (frm_Template), In this form, I have a field called ContractID. I have a command button in this form to open frm_Contract. Frm_Contract has a field called as ContractID too. Now the command button will open frm_Contract in the first record. I would like make it open the frm_Contract based on the ContractID in frm_Template. Ex: If ContractID in frm_Template is A122, the command button in frm+Template will open frm_Contract in record that ContractID is A122. Currently, the open form command code is as follows. How do I adjust to do the above?

Private Sub Templates_Click()
On Error GoTo Err_Templates_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Template"
DoCmd.openForm stDocName, , , stLinkCriteria

Exit_Templates_Click:
Exit Sub

Err_Templates_Click:
MsgBox Err.Description
Resume Exit_Templates_Click

End Sub


Thanks ahead.

NP02

 
are you sure this button opens a form called 'frm_Contract'? it says it is opening a form called "Template"? in any case, add one line and edit another:

Code:
Private Sub Templates_Click()
On Error GoTo Err_Templates_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName =
"frm_Contract"
stLinkCriteria = "ContractID = '" & me.ContractID & "'"
Code:
    DoCmd.openForm stDocName, , , stLinkCriteria

Exit_Templates_Click:
    Exit Sub

Err_Templates_Click:
    MsgBox Err.Description
    Resume Exit_Templates_Click
    
End Sub

what you're doing is adding a 'where' clause.
i know this code was automatically generated by access.
try entering the code yourself and you'll see it prompt you for entries. so start typing
Code:
 docmd.openform
and you'll see it prompt you. then you can see what it's really doing.

hope this helps.


 
Sorry, I mis-copied the code. You are right. The form name need to be changed to frm_Contract. However, I copied the line of stLinkcriteria code to my command button, It does not work. (stii open to the first record).

Any comments?
 
that's messed up.
are you sure?
It should either open the form with one record in it, or no records in it (if there isn't a record in Contracts with that ContractID in it).

when the frm_Contract opens, how many records does it say it has in it (see navigation buttons at the bottom of the form).

is your ContractID a number? or text?
if it's a number, do this instead:

stLinkCriteria = "ContractID = " & me.ContractID

can you see the ContractID's on each of the forms to confirm it is opening incorrectly?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top