Carrying Over Field Value When Opening New Form

miacino

Registered User.
Local time
Yesterday, 19:23
Joined
Jun 5, 2007
Messages
106
I have a MAIN FORM that has field [MR#].
Would like to open a new form VISITS that is a data entry form. Upon opening the VISITS form, I would like the [MR#] in the VISITS form to pre-populate from the MAIN FORM's [MR#].

I'm VERY VERY new to the "coding" side of things in Access.

Under the property sheet on ON LOAD, I put in this code:

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
DoCmd.GoToRecord , , acNewRec
Me.[MR#] = Me.OpenArgs
End If
End Sub

Not working!
Any help is much appreciated!
Michele
 
Make sure the OpenArgs is actually getting passed, put this at the start of your code;

Code:
Debug.Print "Value:" & Me.OpenArgs

And look at the immediate window (Ctrl-G in the debug window)
 
Thanks Minty. I put that code in. In the debug window, after hitting Control G, I get the word "Value:" down below.
 
That means nothing is being passed by to the openargs. Please post up the code that opens the VISITS form ?
 
Code:
 Private Sub Command784_Click()
On Error GoTo Err_Command784_Click
     Dim stDocName As String
    Dim stLinkCriteria As String
     stDocName = "Visits Order"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 Exit_Command784_Click:
    Exit Sub
 Err_Command784_Click:
    MsgBox Err.Description
    Resume Exit_Command784_Click
    
End Sub
 
Good, exactly what we needed. You aren't passing any open Args in the command to open the form. - Adjust the following bit in red to your Control name on the MAIN form.
Code:
 Private Sub Command784_Click()
On Error GoTo Err_Command784_Click
     Dim stDocName As String
    Dim stLinkCriteria As String

    [COLOR="Red"] stLinkCriteria = Me.YourControlHolding_The[MR#]Value[/COLOR]
     stDocName = "Visits Order"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 Exit_Command784_Click:
    Exit Sub
 Err_Command784_Click:
    MsgBox Err.Description
    Resume Exit_Command784_Click
    
End Sub
Also while you are still learning change the field name and remove the # from it. Access uses # characters to identify dates.
Read up here about using a naming convention http://www.access-programmers.co.uk/forums/showthread.php?t=225837 and avoiding spaces and weird characters in object names.
 
As such?
stLinkCriteria = Me.[Text787]

or

stLinkCriteria = Me.[MR#]

The field on the MAIN FORM under properties lists name as Text787, with control source of MR#.

I tried both and still not working. Am I completely confused?

(Thank you for the field naming tip as well... duly noted! Every little tip helps)
 
Got it!

Code:
 Private Sub Command784_Click()
On Error GoTo Err_Command784_Click
     Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "PMD-ADD"
    
    stLinkCriteria = "[mr#]=" & Me![MR#]
    stDocName = "Visits Order"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me![MR#]
 Exit_Command784_Click:
    Exit Sub
 Err_Command784_Click:
    MsgBox Err.Description
    Resume Exit_Command784_Click
    
End Sub

Thank you so much for your patience and guidance!
:D
 
Do pay attention to the tips given with naming convention.
Also consider giving controls meaningful names after creation like txtEndDate, cmdCreateReport.

When you go back to the code n months time later, you will be thankful you did. :-)
 

Users who are viewing this thread

Back
Top Bottom