Results 1 to 5 of 5
  1. #1
    Evans2 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2014
    Location
    Seattle
    Posts
    27

    Trouble with open form command

    Hi all,

    I'm having a heck of time with an Open Form command that has worked for me many times.

    I've used a similar command below for other records and it has always worked with other forms. For some reason, in this case it is not working and I haven't been able to find out why.
    Private Sub ViewLastOrder()
    'bookmark specific record
    DoCmd.OpenForm "frmOrders", , , , , acHidden
    Forms!frmOrders.RecordsetClone.FindFirst "[Invoice_Number]=" & Me.Invoice_Number
    Forms!frmOrders.Bookmark = Forms!frmOrders.RecordsetClone.Bookmark
    Forms!frmOrders.Visible = True


    End Sub

    Then I've got a double click command that calls the ViewLastOrder bookmark based on the invoice number.

    Private Sub LastOrder_DblClick(Cancel As Integer)
    If Me.Invoice_Number = "" Or IsNull(Me.Invoice_Number) Then
    MsgBox "No Order Exists", vbInformation, "Incomplete Data"
    'Me.cboUser.SetFocus
    Exit Sub
    Else

    ViewLastOrder
    End If
    End Sub

    Instead of opening up the last order based on the invoice number, it is opening up all orders and completely ignoring the invoice number limitation.

    I can't think of why this wouldn't work in this case. The form I am opening is a Continuous Form.

    Any help is appreciated.

    Thank you!

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You have nothing in your code to limit the records the form opens with. If you only want to see one record, you need to have a where clause (parameter) in the DoCmd.Openform.

    DoCmd.OpenForm "frmOrders", , ,WhereCondition goes here , , acHidden

    DoCmd.OpenForm "frmOrders", , ,"[Invoice_Number]=" & Me.Invoice_Number , , acHidden

    should work.

    If you include the where condition, you dont need to open the form hidden, and worrk about the bookmarks. Just open it in normal view and it should show you only the one record.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Or you could set a filter on the form
    Code:
    Private Sub ViewLastOrder()
        'bookmark specific record
        DoCmd.OpenForm "frmOrders", , , , , acHidden
        Forms!frmOrders.Filter = "[Invoice_Number]= " & Me.Invoice_Number
        Forms!frmOrders.FilterOn = True
        Forms!frmOrders.Visible = True
    End Sub

  4. #4
    Evans2 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2014
    Location
    Seattle
    Posts
    27
    Thank you! This worked.

  5. #5
    Evans2 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2014
    Location
    Seattle
    Posts
    27
    Thanks! Really appreciate the help.

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

Similar Threads

  1. Where Condition in Open Form Command
    By Srin in forum Access
    Replies: 11
    Last Post: 10-12-2015, 07:26 AM
  2. Using command button to query and open form
    By annienelson621 in forum Forms
    Replies: 2
    Last Post: 03-26-2015, 08:05 AM
  3. Open Form or Command Button problem
    By geordie_taz in forum Forms
    Replies: 3
    Last Post: 12-13-2012, 10:09 AM
  4. Replies: 2
    Last Post: 05-11-2012, 11:52 AM
  5. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 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