Automatically insert control on form (1 Viewer)

123dstreet

Registered User.
Local time
Today, 07:40
Joined
Apr 14, 2010
Messages
122
Hi All! I am having a little trouble finishing this code: I created a button on my sales order Form, when clicked, it opens a new form. On the sales order form there is an Order ID #. On the new form, there is a field for that Order ID #. What I want is for that new form to open and automatically have the Order ID # from the Sales Order Form go into that field. Any thoughts would be appreciated! thanks in advance!




Code:
Private Sub Upgrades_Click()
On Error GoTo Err_Upgrades_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocName = "Upgrades (Form)"
    stLinkCriteria = "[Sales Order]=" & Me.Order_ID
    
    
DoCmd.OpenForm stDocName, , , stLinkCriteria
[COLOR=red][/COLOR] 
[COLOR=#ff0000]What do I put here to make this code work?[/COLOR]
[COLOR=#ff0000][/COLOR] 
Exit_Upgrades_Click:
    Exit Sub
    
Err_Upgrades_Click:
    MsgBox Err.Description
    Resume Exit_Upgrades_Click
End Sub
 

boblarson

Smeghead
Local time
Today, 07:40
Joined
Jan 12, 2001
Messages
32,059
Use the OpenArgs area:

Code:
On Error GoTo Err_Upgrades_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocName = "Upgrades (Form)"
    stLinkCriteria = "[Sales Order]=" & Me.Order_ID
    
    
DoCmd.OpenForm stDocName, , , stLinkCriteria, OpenArgs:= Me.Order_ID

And then in the form's On LOAD event you use:

Code:
If Len(Me.OpenArgs & "") > 0 And Me.NewRecord Then
   Me.YourFieldNameHere = Clng(Me.OpenArgs)
End If
 

123dstreet

Registered User.
Local time
Today, 07:40
Joined
Apr 14, 2010
Messages
122
Thank you kindly! Works like a charm!
 

Users who are viewing this thread

Top Bottom