Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62

    Passing multiple values to a second form

    I see a number examples of passing a single value, but I would like to pass multiple values instead. There are two parts to this as one is the initial data entry and the second is where people can look up previously entered records.



    Here's what each one needs:

    #1
    1. Validate that the key field is filled in.
    2. Pass the needed values into the second form so the user can complete the process on the second form.

    #2
    1. Validate that the key field is filled in.
    2. Do a DB search based on the key field to make sure the record in there first place exists.
    2. Pass the needed values into the second form.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You mean with OpenArgs?

    http://www.baldyweb.com/OpenArgs.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    The value can be passed to a second form by referencing the first form before it is closed.

    Something like

    Me.txtFieldForm2.value = Forms!frmOne.txtField.value

    To check if the value exists in a table already, I would us DAO and .Findfirst with an If Then statement using .Nomatch.

    Code:
    Dim db As DAO.Database
    Dim rcdFindMatch As DAO.Recordset
    Set db = CurrentDb
    Set rcdFindMatch = db.OpenRecordset("tblName", dbOpenDynaset)
        Dim strWhere As String
        
        strWhere = "[CustID] = " & intCustId & " AND [ItemNum] = '" & strItem & "'"
        
        
        rcdFindMatch.FindFirst strWhere
        
            If Not rcdFindMatch.NoMatch Then
            
                MsgBox "This Item number is already listed for this customer", vbInformation, "Matching Item Found"
                
            rcdFindMatch.Close
            Set rcdFindMatch = Nothing
            Exit Sub
            Else
            
                MsgBox "This Item number does not exist for this customer", vbInformation, "Item Not Found"
            
            rcdFindMatch.Close
            Set rcdFindMatch = Nothing
            Exit Sub
            End If

  4. #4
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    I got the values I wanted to get passed in example #1. The form I'm passing the data to has additional fields and those fields have "#Name?" in them when I open the second form. Is there an easy way to clear those out, or do I have to do them on an individual basis?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Clear out the "#Name?" by binding the control to a valid field within the form's recordset. You could also type "Unbound" inside the control to cause it to be an Unbound control.

  6. #6
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    Quote Originally Posted by WithoutPause View Post
    I got the values I wanted to get passed in example #1. The form I'm passing the data to has additional fields and those fields have "#Name?" in them when I open the second form. Is there an easy way to clear those out, or do I have to do them on an individual basis?
    Either something wonky happened with my table or I forgot to add some fields to the table. As I add the fields to the table the #Name? issue goes away. I'll fix this and work on the query aspect.

  7. #7
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    Ok, I had the passing of the data correct and then I began fixing an issue where if a user cleared out the key field after entering data and it still was going to the second form. At some point my data stopped being transferred to the second form. This code works for validation, but fails at actually passing the data.

    Code:
    Private Sub cmdFactSheet_Click()
        C01.SetFocus
        If Trim(C01.Text) = "" Then
            MsgBox "Please enter grievant number."
            Forms!frmComplaint!C01.SetFocus
        Else
            If Not IsNull(C01) Then
                DoCmd.OpenForm "frmFactSheet", , , , , , Me.C01 & ";" & Me.C02 &.... ' There are more fields passed
            End If
        End If
    End Sub

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    So you tested the open args string in your second form? It works when used outside of your If Then Else statement?

  9. #9
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    Well it was but now only the first variable is passed if I take out the if statement. I haven't touched the On Load code so that should be set.

    Code:
    If Not IsNull(Me.OpenArgs) Then
            strOpenArgs = Split(Me.OpenArgs, ";")
            Me.C01 = strOpenArgs(0)
            Me.C02 = strOpenArgs(1)
            Me.C03 = strOpenArgs(2)
    That's the begining of the On Load code.

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    I'd use this method to make sure OpenArgs contains what you expect:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    It doesn't like the strWhere line saying there is a data type mismatch.

    Code:
    If Not IsNull(Me.C01) Then
        '
        Dim db As DAO.Database
        Dim rcdFindMatch As DAO.Recordset
        Set db = CurrentDb
        Set rcdFindMatch = db.OpenRecordset("Complaint", dbOpenDynaset)
            Dim strWhere As String
            
            strWhere = "[C01] = " & C01
            
            rcdFindMatch.FindFirst strWhere
            
            If rcdFindMatch.NoMatch Then
                MsgBox "The grievant number does not exist", vbInformation, "Grievant Number Not Found"
                rcdFindMatch.Close
                Set rcdFindMatch = Nothing
                C01.SetFocus
                Exit Sub
            Else
                DoCmd.OpenForm "frmFactSheet", acNormal, , , , , C01.Value
            End If
        '
    Else
        Debug.Print "y"
        MsgBox "Please enter grievant number."
        Me.C01.SetFocus
    End If

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    If the field is text you need delimiters:

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    When you reference a control in VBA you should use the collection name

    Forms!frmName![ControlName]

    You can also use the Me shortcut if the control is on the form's class module you are working in

    Me.ControlName

    try
    strWhere = "[C01] = " & Me.C01

    What data type is Me.C01?

  14. #14
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    Me.C01 is a text field. I tried passing more than one field and I got an error message. I had though it just needed to add & ";" & between what fields were being passed.

    Works:
    Code:
    DoCmd.OpenForm "frmFactSheet", , , "C01 = '" & Me.C01 & "'"
    Doesn't work:
    Code:
    DoCmd.OpenForm "frmFactSheet", , , "C01 = '" & Me.C01 & "'" & ";" & "C02 = '" & Me.C02 & "'"

  15. #15
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    A wherecondition wouldn't be separated by ";", rather by " AND ".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. passing values from form to query
    By gregd in forum Access
    Replies: 6
    Last Post: 05-02-2013, 03:18 PM
  2. Replies: 5
    Last Post: 10-15-2012, 12:18 AM
  3. Passing Multiple selection values to a report
    By techexpressinc in forum Forms
    Replies: 7
    Last Post: 01-13-2012, 02:27 PM
  4. Replies: 1
    Last Post: 03-24-2010, 08:42 AM
  5. Replies: 3
    Last Post: 06-02-2009, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums