If Then Else...?

bhaycox

New member
Local time
Today, 14:25
Joined
Feb 2, 2008
Messages
9
Hi,

I have not used Access or VB for ages and am a little rusty.

I have created a database to generate letters, there are only 2 users if userA enters details and then needs print off the report I want his personal details at the bottom of the report (tel no. email etc). The form is pretty standard to fill in the user then selects either userA or userB via a drop down.

Do I use an If Then Else to display the appropriate label? and if so how and where do I structure it?

It's probably a basic one but I just can't figure it out.

If Consultant = userA Then
labelUserAdetails.visible = true
Else
labelUserBdetails.visible = true
End If


Thanks in advance

Ben
 
Ben

Need more info, but you probably want to use the Form's OnCurrent event
to do this. You could also use Conditional Formatting.

Code:
If Consultant = userA Then 
   labelUserAdetails.visible = true
   labelUserBdetails.visible = False
Else
   labelUserAdetails.visible = False
   labelUserBdetails.visible = true
End If

Wayne
 
Hi Wayne & Adam,

I sorted it with is:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Consultant = "Benjamin Haycox" Then
lblBen.Visible = True
lblChelle.Visible = False
Else
lblChelle.Visible = True
lblBen.Visible = False
End If
End Sub

Thanks for the feedback

Ben
 
Last edited:
Hi Wayne & Adam,

I sorted it with is:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Consultant = "Benjamin Haycox" Then
lblBen.Visible = True
lblChelle.Visible = False
Else
lblChelle.Visible = True
lblBen.Visible = False
End If
End Sub

Thanks for the feedback

Ben

This is not a good way of doing this. What happens if "Benjamin Haycox" leaves. His name is hard coded into the report and somebody has got to find it and re-code.

Why not have a footer that picks up the username from a function such as Environ("username")


HTH
 
Thanks for the reply Fear Naught,

It's a valid point and worth pointing out to anyone developing a database for an organisation.

I on the other hand am Benjamin Haycox and the only other user is my wife. The only other director of the company is my daughter and she's off to uni in september and has no interest in being a property consultant. The database is just to make it easy to print standard letters off so I thought I'd have a bash at it myself. It works too.


Cheers for the help everyone.

Ben
 

Users who are viewing this thread

Back
Top Bottom