Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-02-2009, 04:24 AM
joe41 joe41 is offline
Spammer
 
Join Date: 26 Feb 2009
Location: U.S
MS Office Version:Outlook
Posts: 59
joe41 is becoming part of the community
If database has no records, disable click button

Please Register to Remove these Ads

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?
Reply With Quote
  #2  
Old 06-02-2009, 12:59 PM
split_atom18 split_atom18 is offline
Forum Contributor
 
Join Date: 23 Apr 2009
Location: Fredericksburg, IA
MS Office Version:Ultimate 2007
Posts: 126
split_atom18 Has established their mark in the community
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!
Reply With Quote
  #3  
Old 06-30-2009, 07:03 AM
joe41 joe41 is offline
Spammer
 
Join Date: 26 Feb 2009
Location: U.S
MS Office Version:Outlook
Posts: 59
joe41 is becoming part of the community
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.
Reply With Quote
  #4  
Old 06-30-2009, 10:35 AM
split_atom18 split_atom18 is offline
Forum Contributor
 
Join Date: 23 Apr 2009
Location: Fredericksburg, IA
MS Office Version:Ultimate 2007
Posts: 126
split_atom18 Has established their mark in the community
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!
Reply With Quote
  #5  
Old 06-30-2009, 10:39 AM
split_atom18 split_atom18 is offline
Forum Contributor
 
Join Date: 23 Apr 2009
Location: Fredericksburg, IA
MS Office Version:Ultimate 2007
Posts: 126
split_atom18 Has established their mark in the community
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!
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump