Results 1 to 6 of 6
  1. #1
    mwabbe is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    79

    Opening a form with openargs and things

    Code:
    If Me.NewRecord Then
       DoCmd.OpenForm "Benefits", , , , , acDialog, Me.ID & ";" & Me.First_Name & ";" & Me.Last_Name
    Else
         DoCmd.OpenForm "Benefits", , , "[EmployeeID]=" & Me.ID, , acDialog
    End If
    Have a form "EmpInfo" with a button that has the above code that opens "Benefits" in different ways depending on if its a new record or not.



    Lets say the user is entering in an employee on the EmpInfo form and some catastrophe happens where they have to save close the form and then when they go back and open it up and click this button, it doesnt do the first one because since it was closed it is not a new record anymore so it wont pass what i want it to the next form. I believe it does the second because its not a newrecord anymore but Benefits still comes up with no information on it.

    as of now to get this to work the user has to go through all the forms to get this to link correctly and then when they open the record bakc up the button works fin.

    any tips would be appreciated.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Always use the NewRecord method to open the Benefits form and use the OnLoad event of the Benefits form to make your decision on the filter.

  3. #3
    mwabbe is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    79
    what i have hear works in two conditions, i mean it works in the two that are specified when the record is new and when its not

    Example: I am typing information in about an employee on the EmpInfo form I hit the save button and the form resets to a new record. the save button does not do either of the two lines above, resulting in: the openargs were not passed and now the form is not new.

    so the next time i want to continue entering information about that employee i open up there EmpInfo form and hit the Benefits button and nothing was passed the first time so it brings up a blank Benefits page instead of a corresponding Benefits form with the empid, f name, and l name

    is there a way so that if this happens to be able to use the button the intended way to open benefits?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    As I said, if you always open the 1st way then the OnLoad event of the next form can turn start the form by looking up the [EmployeeID] and go to the record if it exists or start a new record if not. No decision needed on the 1st form and the presents of the OpenArgs arguments (or lack of them) allows the form make all of the decisions needed.

  5. #5
    mwabbe is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    79
    I appreciate the help but I am drawing a complete blank on how to do this

    here is the code for OnLoad event of Benefits:
    Code:
    Private Sub Form_Load()
    Dim strOpenArgs() As String
    
        If Not IsNull(Me.OpenArgs) Then
            DoCmd.GoToRecord , "", acNewRec
            strOpenArgs = Split(Me.OpenArgs, ";")
            Me.EmployeeID = strOpenArgs(0)
            Me.Text44 = strOpenArgs(1)
            Me.Text46 = strOpenArgs(2)
        End If
    
    
    DoCmd.Close acForm, "EmpInfo"
    
    End Sub
    do I add in Me.FilterOn and Me.Filter?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This is pure AIR CODE but something like:
    Code:
    Private Sub Form_Load()
       Dim strOpenArgs() As String
       If Not IsNull(Me.OpenArgs) Then
          strOpenArgs = Split(Me.OpenArgs, ";")
          ' Find the record that matches the control.
          Me.Recordset.FindFirst "[EmployeeID] = " & strOpenArgs(0)
          If Me.RecordsetClone.NoMatch Then
             DoCmd.RunCommand acCmdRecordsGoToNew
             Me.EmployeeID = strOpenArgs(0)
             Me.Text44 = strOpenArgs(1)
             Me.Text46 = strOpenArgs(2)
          Else
             If Len(Me.Text44 & "") = 0 Then
                Me.Text44 = strOpenArgs(1)
             End If
             If Len(Me.Text46 & "") = 0 Then
                Me.Text46 = strOpenArgs(2)
             End If
          End If
       End If
       '  By using the OpenArgs arguments you can close the previous form without waiting.
       '  DoCmd.Close acForm, "EmpInfo"
       '  If you opened this form using the Dialog argument then you do not want the previous form closed
       '  as that is where you will return when this form is closed.
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Start form on opening database
    By Ted C in forum Forms
    Replies: 2
    Last Post: 08-10-2010, 08:00 PM
  2. Opening one report for current form???
    By GEPC in forum Reports
    Replies: 1
    Last Post: 07-15-2010, 10:46 AM
  3. Error In Opening Form
    By cwwaicw311 in forum Forms
    Replies: 1
    Last Post: 03-10-2010, 09:18 AM
  4. Things moving around on my form
    By jlm722 in forum Forms
    Replies: 0
    Last Post: 09-30-2009, 03:34 PM
  5. Replies: 2
    Last Post: 09-01-2006, 04:03 PM

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