Results 1 to 10 of 10
  1. #1
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26

    Question Using search combo box when form opened in 'Add' mode

    I have a form containing command buttons to open various other forms within the project. I've specified that the form be opened in add mode, however I had previously created a search combo box in the form header, to enable users to find a record. This combo box works if I code the button to open the form in edit mode, but this also causes the form to open at the first record, thereby requiring users to hit another button to add a record.
    Is there a way to code the form to enable it to be opened at a new record, but also allowing users to navigate to an already existing record using the combo box, and edit records?

    The code on the command button is currently:



    DoCmd.OpenForm "frmCONTACTS", acNormal, , , acFormAdd, acDialog

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use DoCmd.GoToRecord, either in that code or in the load event of the form being opened.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26
    Thanks Paul - I'd mistakenly put that command in the On Current event, not the load event! Very new to databases and coding, as you've no doubt guessed.
    Grateful for your assistance.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! Having it in the current event would make it tough to go to other records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26
    Oops! Still having a problem. The combo box no longer works when the forms are opened from the command buttons. I've tried simply opening forms from the navigation pane, and they still work there. Curiously, one of the forms opens and works from the 'OpenForm' form, but the other 4 don't??? See code below for frmINSPECTION. Any ideas???

    Dim rs As DAO.Recordset
    If Not IsNull(Me.Combo49) Then
    'Save before move.
    If Me.Dirty Then
    Me.Dirty = False
    End If
    'Search in the clone set.
    Set rs = Me.RecordsetClone
    rs.FindFirst "[ContactID] = " & Me.Combo49
    If rs.NoMatch Then
    MsgBox "Not found: filtered?"
    Else
    'Display the found record in the form.
    Me.Bookmark = rs.Bookmark
    End If
    Set rs = Nothing
    End If

  6. #6
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26
    Blimey - just pasted the wrong window!

    Code for combo box on frmInspection as follows:

    Private Sub Combo16_AfterUpdate()
    'Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.RecordsetClone
    rs.FindFirst "[InspectionID] = " & Str(Nz(Me![Combo16], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark


    End Sub

  7. #7
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26
    Think I'm getting there???
    I've removed the On Load code, and modified the Click event for each button that opens a form, to the following (seems to be working)

    'Open the form to a new record, but also allow combo box searches for existing records
    DoCmd.OpenForm "frmINSPECTION"
    DoCmd.GoToRecord acDataForm, "frmINSPECTION", acNewRec

  8. #8
    alcapps is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    292
    here is another way to get to a new record..
    Private Sub Form_Open(Cancel As Integer)
    Me.DataEntry = True
    End Sub

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Looks like you've got it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    jfn15 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    26
    Many thanks to all for your assistance!

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

Similar Threads

  1. Replies: 7
    Last Post: 08-08-2012, 03:28 PM
  2. Replies: 1
    Last Post: 04-20-2012, 03:16 AM
  3. Combo box requery issue in tabbed form mode
    By michael0610 in forum Access
    Replies: 9
    Last Post: 11-17-2011, 03:22 PM
  4. Replies: 2
    Last Post: 09-01-2011, 10:48 PM
  5. Replies: 4
    Last Post: 01-14-2011, 10:37 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