Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    United Kingdom
    Posts
    56

    Unanswered: OnClick Event to run if table is empty

    Hey Guys,

    I have a form with a command button that needs to run some code ONLY if the table "PROJECT" is empty and has no data in it.

    How can I do this - do I use the standard "If" argument?

    Any help would be greatly appreciated.

    Rusty


    Code:
    If ... Then
    Docmd...

    Else

    End If
    End Sub

  2. #2
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    Try creating a recordset of the table and checking to see if there are any records. Put this in your button's OnClick event:

    Code:
    Dim rst as ADODB.Recordset
    
    Set rst = New ADODB.Recordset
    rst.Open "SELECT * FROM PROJECT;", CurrentProject.Connection, _
       adOpenKeyset, adLockOptimistic
    
    If rst.EOF Then
       'table is empty, run code here
    Else
       'table is not empty, run code here
    End If
    
    rst.Close
    Set rst = Nothing

  3. #3
    Join Date
    Apr 2004
    Location
    United Kingdom
    Posts
    56
    I couldn't get that to work - but thanks for the help.

    I ended up going with:

    If DCount("[FieldName]", "TableName") = 0 Then

    Cheers,

    Rusty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •