+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Spammer
    Join Date
    02-26-2009
    Location
    U.S
    MS-Off Ver
    Outlook
    Posts
    59

    If database has no records, disable click button

    Hello friends,

    I have a database what i wanna to do is that if the database has no records then disable the click button.

    I have buttons that "Go to the next record" and that "Complete the record" (put a time stamp in the record that it's been worked)

    The problem is that the form is based on a query, and once all records have timestamps there are no records for the query. So when you click the "Go to next record button" it errors out. There is no record.

    Than in advance.

    I do have a counter on my form, that tells you how many records are left. When they are all gone, that also vanishes (it's just a groupby and sum)

    Is there a way for me to have the VB code look at the countup querry, and if there are no records, have the button not work?

  2. #2
    Valued Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    233

    Re: If database has no records, disable click button

    You want to do a recordcount. There are several ways to do this, pick one:

    SQL
    Code:
    SQLstmt = "SELECT Count(*)" & _
    " FROM tbltimestamps"
    
    Set RCountDB = CurrentDb
    Set RCountRS = RCountDB.OpenRecordset(SQLstmt)
    YourCount = RCountRS.Fields(0) ...
    DCount Function
    Code:
    YourCount = DCount("*", "tbltimestamps") ...
    From Northwind 2007 Database
    Code:
    Dim rsw As New RecordsetWrapper
            With rsw.GetRecordsetClone(Me.sbfOrderDetails.Form.Recordset)
                ' Check that we have at least one specified line items
                If .RecordCount = 0 Then
                    MsgBoxOKOnly OrderDoesNotContainLineItems
                Else
                    ' Check all that all line items have allocated inventory
                    Dim LineItemCount As Integer
                    Dim Status As OrderItemStatusEnum
                    LineItemCount = 0
                    While Not .EOF
                        LineItemCount = LineItemCount + 1
                        Status = Nz(![Status ID], None_OrderItemStatus)
                        If Status <> OnHold_OrderItemStatus And Status <> Invoiced_OrderItemStatus Then
                            MsgBoxOKOnly MustBeAllocatedBeforeInvoicing
                            Exit Function
                        End If
                        rsw.MoveNext
                    Wend
                                            
                    ValidateOrder = True
                End If
            End With
    So something like:
    Code:
    IF myrecordcount = 0 then
       me.buttonname.enabled = False
    Else
       me.buttonname.enabled = True
    End if
    Hope this helps,

    Dan
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!

  3. #3
    Spammer
    Join Date
    02-26-2009
    Location
    U.S
    MS-Off Ver
    Outlook
    Posts
    59

    Re: If database has no records, disable click button

    Thanks very much for your reply but can you tell me which one is the suitable for me to disable a button when there is no record in the database.

  4. #4
    Valued Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    233

    Re: If database has no records, disable click button

    Nope, sorry, not without seeing/knowing more about your database. I gave you 3 different ways to do it and put a general suggestion at the bottom. Without more information I can't really help you more.

    Sorry,

    Dan
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!

  5. #5
    Valued Forum Contributor
    Join Date
    04-23-2009
    Location
    IOWA
    MS-Off Ver
    2010 Professional
    Posts
    233

    Re: If database has no records, disable click button

    Basically I gave you 3 ways to Count the Records. After that you need an if then statement.

    Code:
    If whateverIusedtocountrecords = 0 then
        me.buttontodisable.enabled = False
    Else
        me.buttontodisable.enabled = True
    End If
    So technically all 3 are suitable
    "I am not a rocket scientist, I am a nuclear engineer." - Split_atom18
    If my advice has been helpful to you, then please help me by clicking on the scales and adding to my reputation, Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0