Results 1 to 2 of 2
  1. #1
    MiaAccess is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Texas
    Posts
    31

    open form if no records in query

    When leaving a form as part of the exit button code, I want to test if there are records and a particular field is empty.



    I created a query and if there are records, a form created from the query should open and show the missing items; however, if the query has no records, it should just continue on. This is for right now my easy way out until I can figure out why my record validation doesn't work.

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    You could also write a simple function to return a true or false if there are records in the table.

    ex (using ADO and passing a value to the function):

    Function retHasRecords(SomeValue as variant) as boolean
    retHasRecords = false
    dim rs as adodb.recordset
    set rs = new adodb.recordset
    dim strSQL as string
    strSQL = "Select * from MyTableName where SomeFieldName = '" & SomeValue & "'"
    rs.open strSQL, currentproject.connection, adopenkeyset, adlockreadonly
    if rs.eof and rs.bof then
    retHasRecords = false
    else
    retHasRecords = true
    end if
    rs.close
    set rs = nothing
    end Function


    Save this function in a module to call it from any form. You could also write a simple function to test your validation and return true or false depending on what the function checks. This is much better than putting validation into the table design if that is how you setup your validation.

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

Similar Threads

  1. Replies: 29
    Last Post: 02-13-2011, 01:21 AM
  2. Open form to filtered records
    By ducecoop in forum Access
    Replies: 3
    Last Post: 10-22-2010, 10:53 AM
  3. Replies: 2
    Last Post: 02-26-2010, 08:14 AM
  4. Open form based on query results
    By RobbertH in forum Queries
    Replies: 1
    Last Post: 02-10-2010, 08:13 AM
  5. Open a form using a query that references a combo
    By accessbobp646 in forum Access
    Replies: 1
    Last Post: 02-22-2009, 09:50 AM

Tags for this Thread

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