|
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!
|