Enabling Controls Dependant Upon Criteria

TheEvilBankers

Registered User.
Local time
Today, 08:17
Joined
Aug 13, 2003
Messages
33
Enabling and Disabling buttons on a Form based on criteria found in a Table

We have a form that has two buttons one is a normal print button the other is a reprint button. Upon opening the database we would like it to check the date in a table called FSU to see if a record has been generated for the day. If there is a record then the reprint button will be active and visa versa.

This is the code we have...


Private Sub Form_Load()
Dim strDate As String
Dim rsDateCheck As New ADODB.Recordset

rsDateCheck.Open "FSU", CurrentProject.Connection
rsDateCheck.MoveFirst

If strDate = Date Then
Me.Reprint_FSU.Enabled = True
Me.FSU_print.Enabled = False
End If
rsDateCheck.Close
End Sub

Thanks.
A and K
 
Evil,

If you are just looking for the presence of
a record. Then you can use the DCount function
to check that.

Code:
If Nz(DCount(...), 0) > 0 Then
   ' Is a record
Else
   ' No record
End If

The Help files will show you an example.

Wayne
 
We are looking for a record with the current date, not just that a record exists.


The table consists of a sequential number and a date field.

Do you think DLookup would work better in this situation?

Thank you
The EvilBankers
 
Evil,

The DCount should be an easy way to do this.

Code:
If Nz(DCount("[DateField]", "YourTable", "[DateField] = #" & Date & "#"), 0) > 0 Then
   MsgBox("There is a record.")
End If

Wayne
 
Wayne,

You are a god!!!!

It worked perfectly.

We have been fiddling with this for the past 3 days.

The Evil Bankers
 

Users who are viewing this thread

Back
Top Bottom