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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open form, populate textbox

Status
Not open for further replies.

beenut23

Technical User
Aug 17, 2008
8
hello!

I have a button on a form, which when clicked, opens another form. The code for my button is:

Code:
Private Sub cmdOpenDispo_Click()

Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmDispoForm"
    stLinkCriteria = "CaseID=" & Me.txtCaseID
    
    
    DoCmd.Save
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Debug.Print Me.txtCaseID

End Sub

My problem is that it is not putting the value that is in Me.txtCaseID into the CaseID on the form when it opens it. The Debug.Print does work, so it is seeing that value.

Any ideas why it's not working? it's supposed to open to a new record, and plug that CaseID into it.

Thanks much for your help.

 
I noticed that the Me.txtCaseID appears to be 'text'. If that's so then try:
stLinkCriteria = "CaseID='" & Me.txtCaseID & "'"
This will send the varaible as text
 
This was the solution:

Private Sub cmdOpenDispo_Click()

Dim stDocName As String

stDocName = "frmDispoForm"

DoCmd.OpenForm stDocName, , , , acFormAdd

Forms!frmDispoForm!txtCaseID = Me.txtCaseID

End Sub

that way it opens to a new record with the specific CaseID I wanted. thanks!
 
Correct Beenut, to clarify, the link criteria is used to locate an existing record. If a record had existed with the value you were passing, it would have opened the form at that record.

If you want to create a new record you must not use a link criteria, you must set the values of the desired control as Beenut has shown above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top