Results 1 to 3 of 3
  1. #1
    GraemeG is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Feb 2011
    Posts
    152

    Primary Key and form

    Hi,

    I have a (pre record selector) form with one text box to enter a primary key to then open the main form to the specific record.
    using

    [CODE][Private Sub CmdSearch_Click()
    DoCmd.OpenForm "Internal Survey Form", , , "Propref = '" & Me.txtPropref & "'"
    End Sub/CODE]

    It still opens to a blank form if there is no record matching.


    How can I prevent the main form opening and have a message saying no record found?

    Thanks
    Graeme

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    Some logic/pseudocode. prior to opening the form, open a recordset (rst) with the same criteria. if rst.bof AND rst.eof THEN msgbox "empty" ELSE OpenForm.

    Basically, you're checking to see if the first entry of the recordset is both the begining and the end of the recordset. If true, then it's empty and you can throw and error msg.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Add a DLookup() first in your code and only execute the OpenForm if the key is found. DLookup() usage examples: http://access.mvps.org/access/general/gen0018.htm

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

Similar Threads

  1. Replies: 3
    Last Post: 03-11-2012, 08:20 AM
  2. Replies: 1
    Last Post: 06-15-2011, 03:29 PM
  3. Replies: 2
    Last Post: 12-08-2010, 01:32 PM
  4. How do you refer to primary key on split form?
    By techneophyte in forum Forms
    Replies: 3
    Last Post: 08-13-2010, 08:11 AM
  5. Send Primary Key from a Form To A Report
    By nkuebelbeck in forum Forms
    Replies: 1
    Last Post: 03-18-2010, 12:24 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