Consulting

Results 1 to 2 of 2

Thread: OpenArgs Statement

  1. #1
    VBAX Regular
    Joined
    Dec 2012
    Posts
    7
    Location

    Question OpenArgs Statement

    Hi Guys & Girls,

    Thanks in advance for your help.

    I presently have this problem. I have a reminders form that Opens from a variety of different forms, for arguments sake let's say Production and Meeting both have a button with an OnClick events then leads to the following line of code;

    DoCmd.OpenForm "frmEmail", , , , acFormAdd, , Me.[ProductionID]
    DoCmd.OpenForm "frmEmail", , , , acFormAdd, , Me.[MeetingID]
    The problem occurs when I have the
    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
      DoCmd.GoToRecord , , acNewRec
      Me.[ProductionID] = Me.OpenArgs
    End If
    End Sub
    I want the OpenArgs to be variable to allow for the correct ID to be dropped in the relevant combo box. I have tried;

    Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
      DoCmd.GoToRecord , , acNewRec
      Me.[ProductionID] = Me.OpenArgs
    Me.[MeetingID] = Me.OpenArgs
    End If
    End Sub
    Addmitedlty, the logic dosen't work forme I would have to write another statement however I've spent to long dumbfounded and was hoping you guys & girls could give me a little help.

    Many Thanks,

    Will

  2. #2
    One way to handle this is to pass more information in the OpenArgs.

    Example:

    DoCmd.OpenForm "frmEmail", , , , acFormAdd, , "ProductionID," & Me.[ProductionID]


    and


    DoCmd.OpenForm "frmEmail", , , , acFormAdd, , "MeetingID," & Me.[MeetingID]

    Then use this:

    Private Sub Form_Load() 
    
      Dim strControlName as String
      Dim lngID as Long
    
        If Not IsNull(Me.OpenArgs) Then 
            ' retrieve the control name from the OpenArgs
           strControlName = Left(Me.OpenArgs, Instr(Me.OpenArgs(), ",") -1)
    
          ' Retrieve the ID from OpenArgs
          lngID = Mid(Me.OpenArgs,Instr(Me.OpenArgs(), ",")+1)
    
                  'Go to a new record
          DoCmd.GoToRecord , , acNewRec 
    
                  ' set the control with the ID
          Me(strControlName =  lngID
        End If 
    End Sub
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •