Results 1 to 7 of 7
  1. #1
    mb88 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    3

    Create new record if filter returns no record

    Hi all,

    First up - I'm brand spanking new to the database and coding world, so the complete and utter dumbing down of any responses would be awesome.

    I got the code below from the web. The goal is to filter the records in qryNeighbours by the burn number that is selected in cboBurnNumber. This code worked for a dataset in which all of the possible burn numbers are present. My problem is that the qryNeighbours data set does not yet contain any data - the idea being that people will select a burn number then input into a new record - and as such (I'm assuming) is spitting out an error because the filter can't find a match.

    Can anyone offer any suggestions?

    ------------
    Sub SetFilterNeighbours()

    Dim LSQL As String



    LSQL = "select * from qryNeighbours"
    LSQL = LSQL & " where BurnNumber = '" & cboBurnNumber & "'"

    Form_frmNeighbour.RecordSource = LSQL
    -------------


    End Sub

    Cheers!
    Michael

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Try:

    With Me.RecordsetClone
    .FindFirst "BurnNumber='" & Me.cboBurnNumber & "'"
    If .NoMatch Then
    DoCmd.GoToRecord , , acNewRec
    Else
    Me.Bookmark = .Bookmark
    End If
    End With
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mb88 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    3
    Thanks for the reply!

    Again, completely new to this - Is this intended to replace the code I have, or work with it?

    Just to further explain in case it changes the scenario;
    I have a number of forms in a navigation form. I want all of them to link to the combo box in the header which acts as the filter for all forms (see attached image)

    Click image for larger version. 

Name:	ScreenDump.jpg 
Views:	34 
Size:	85.4 KB 
ID:	13113

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    It was intended to replace.

    However, use of navigation form might complicate. I don't like and don't use navigation form. It confuses me.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Gambit17 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    26
    Yeah I am also Brand Spanking new to MS Access and would also like to implement something similar. Whereby when entering information into a form, the form checks if it is duplicate info, tells the user if it is and takes them to the original form. Is this possible?

    Sorry for Hijacking your post mb88

    Thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Yes, that is possible, perhaps with code similar to already suggested which uses unbound controls to enter search criteria or with code in a combobox NotInList event. All depends on individual situation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    mb88 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    3
    That's cool Gambit17!

    Thanks for the suggestion June7,

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

Similar Threads

  1. Replies: 12
    Last Post: 10-27-2012, 05:44 AM
  2. Replies: 5
    Last Post: 08-21-2012, 12:30 PM
  3. Replies: 22
    Last Post: 06-12-2012, 10:02 PM
  4. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  5. Report only returns 1 record unless run directly
    By teresamichele in forum Reports
    Replies: 3
    Last Post: 12-17-2010, 12:06 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