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

Help with OpenArgs code to pass data from one form to an opening form 1

Status
Not open for further replies.

RobertIngles

Technical User
Jan 20, 2011
113
0
0
CA
I have learned a tremendous amount from you MVP's, thank you.

On this one I am totally confused about the OpenArgs and have tried several variations of code I found on the web but nothing works.

I am trying to pass data in a field from Form1 to a field of the same name in an opening form2 which opens based on the user response in a MsgBox. I know I have to use the OpenArgs code but have had no luck so I am blatantly asking for code instructions instead of telling you what I have tried and asking for a correction.

The user enters data into the [Barcode] field of Form1 which searches for a match. If no match is found, the user is asked if they would like to create a new profile. If Yes, then Form2 opens in add mode - I want the value they searched on in Form1 ([Barcode]} to be passed to the [Barcode] field in Form2.

I really need both the code needed in Form1 that makes the data available to Form2 and the OnLoad OpenArgs code to pull the data into the [Barcode] field of Form2

Here is the code as it currently stands:

Option Explicit
Private Sub Command4_Click()
'Create var.
Dim intChk As Integer

'This line counts the number of rec instances in TBLLaptop.
intChk = DCount("*", "tblLaptop", "Barcode = '" & Forms!FRM_Search_To_Update_Encryption_Status!Barcode & "'")


'Does the rec exist? If not then open FRMCreateNewLaptopandUser_Encryption to add the new user details.
If intChk = 0 Then 'No?

Dim response As Long

response = MsgBox("This Laptop Does Not Exist, Do You Wish to Create Laptop Profile", vbYesNo + vbQuestion, "Create New Laptop Profile?")
Me.Barcode = Null

If response = vbYes Then DoCmd.OpenForm "FRMCreateNewLaptopandUser_Encryption", , , , acFormAdd

Else

DoCmd.RunMacro "MacroUpdateLaptopEncryption"

End If

End Sub

Thank you for your help!!
 
How are ya RobertIngles . . .

Using [blue]OpenArgs[/blue] is a two step process:
[ol][li]You [blue]set[/blue] OpenArgs in the calling form to pass it.[/li]
[li]You [blue]read[/blue] OpenArgs in the called form to use it.[/li][/ol]
So ... in your calling form you should have:
Code:
[blue]   Dim Cri As String, DL As String, frmName As String
   
   DL = vbNewLine & vbNewLine
   frmName = "FRMCreateNewLaptopandUser_Encryption"
   Cri = "[Barcode] = '" & Me.BarCode & "'"
   
   If DCount("[BarCode]", "tblLaptop", Cri) = 0 Then
      If MsgBox("This Laptop Does Not Exist!" & DL & _
                "Do You Wish to Create Laptop Profile", _
                vbYesNo + vbQuestion, _
                "Create New Laptop Profile?") = vbYes Then
         DoCmd.OPenForm frmName, , , , acFormAdd, , Me.BarCode
      Else
         DoCmd.RunMacro "MacroUpdateLaptopEncryption"
      End If
   End If[/blue]
Then in the [blue]OnLoad[/blue] event of [blue]FRMCreateNewLaptopandUser_Encryption[/blue] its:
Code:
[blue]   Me.Barcode = Me.[purple][b]OpenArgs[/b][/purple][/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks AceMan - it works and I went through your code line by line and now feel I have a good understanding of this VB process!

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top