help with IF and AND statments

bigmac

Registered User.
Local time
Today, 00:41
Joined
Oct 5, 2008
Messages
302
hi all, i am new to vba and need some help please ,
i have the folloing code
Private Sub Report_Load()
If lngMyEmpID = 1 Then
Me.pm1.Visible = True
this works ok but what i would like after checking lngMyEmpID to see if its true i also want to be able to look at another cell [date1] and compare the date in that cell with todays date and if it is older than todays date only then will Me.pm1.Visible = True
can you help please
 
So add another If..
Code:
Private Sub Report_Load()
    If lngMyEmpID = 1 Then
        If Me.date1 > Date() Then
            Me.pm1.Visible = True
        End If
    End If
End Sub
EDIT: Reading the topic again.. You can also do..
Code:
Private Sub Report_Load()
    If lngMyEmpID = 1 And Me.date1 > Date() Then
            Me.pm1.Visible = True
    End If
End Sub
 
Last edited:
Depending on where you are doing this, you may have to account for the else case as well.
Code:
Private Sub Report_Load()
    If lngMyEmpID = 1 And Me.date1 > Date() Then
            Me.pm1.Visible = True
    Else
        Me.pm1.Visible = False
    End If
End Sub
 
Or, a bit condensed:
Code:
 Me.pm1.Visible = ( lngMyEmpID = 1 And Me.date1 > Date() )
 

Users who are viewing this thread

Back
Top Bottom