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?
You want to do a recordcount. There are several ways to do this, pick one:
SQL
DCount FunctionCode:SQLstmt = "SELECT Count(*)" & _ " FROM tbltimestamps" Set RCountDB = CurrentDb Set RCountRS = RCountDB.OpenRecordset(SQLstmt) YourCount = RCountRS.Fields(0) ...
From Northwind 2007 DatabaseCode:YourCount = DCount("*", "tbltimestamps") ...
So something like: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
Hope this helps,Code:IF myrecordcount = 0 then me.buttonname.enabled = False Else me.buttonname.enabled = True End if
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!
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.
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!
Basically I gave you 3 ways to Count the Records. After that you need an if then statement.
So technically all 3 are suitableCode:If whateverIusedtocountrecords = 0 then me.buttontodisable.enabled = False Else me.buttontodisable.enabled = True End If
"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!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks