Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    173

    Unanswered: Problem with OpenArgs when Form is Open

    I have some issues with OpenArgs

    The code shown below works perfectly if the form I am trying to open (Demo2) is closed... but if the form (Demo2) is Open, it will not go to the desired record.

    How can I make it go to the specified record if the form (frmDemo2) is open?


    on the form showing the Orders (Demo1), I have A Command Button to Open the Customer Form - see code below:



    Private Sub cmdOpenDemo2_Click()
    If Nz(Me.txtCustomerId, 0) > 0 Then DoCmd.OpenForm "frmDemo2", acNormal, , , acFormEdit, acDialog, Me.txtCustomerID
    End Sub


    in the OnOpen event of frmDemo2, (Customer Form) I have the following code...

    If Not IsNull(Me.OpenArgs) Then
    Dim RS As DAO.Recordset
    Set RS = Me.RecordsetClone
    RS.FindFirst "CustomerID = " & Me.OpenArgs
    If Not RS.NoMatch Then
    Me.Bookmark = RS.Bookmark
    End If
    End If



    If the Customers form (Demo2) is closed, it will open the the specified record - but if (Demo2) is Open, it will not navigate to the record I want it to...



    Any help is appreciated - AB

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    I think it's "in the name" here, OpenArgs and On Open - they won't fire/have new values unless you open it.

    One thing to try:
    Code:
    Private Sub cmdOpenDemo2_Click()
      dim frm as form
      dim rs as dao.recordset
      If Nz(Me.txtCustomerId, 0) > 0 Then 
        if currentproject.allforms("frmDemo2").isloaded then
          set frm = forms("frmDemo2")
          set rs = frm.recordsetclone
          rs.findfirst "CustomerID = " & Me.txtCustomerID
          if not rs.nomatch then frm.bookmark=rs.bookmark
          set rs=nothing
          frm.setfocus
          set frm=nothing     
        else
          DoCmd.OpenForm "frmDemo2", acNormal, , , acFormEdit, acDialog, Me.txtCustomerID
        end if
      end if
    End Sub
    Note - would require version 2000+, for prior versions, replace the isloaded thingie here with the isloaded function found in the Northwind sample database - typed not tested...
    Roy-Vidar

  3. #3
    Join Date
    Aug 2004
    Posts
    173
    Thank You! - That works perfectly!!!

    AB

Posting Permissions

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