Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alert Text with coding 2

Status
Not open for further replies.

WebGodiva

Technical User
Jun 21, 2000
263
US
I am not that good using code to make things work and i just can't figure this out.

I need to create a message alert based on two fields. If the fields (GuestFirstName and GuestLastName) equal a specific value (i.e. John Smith), then a message needs to show up that reads "Offering Full Credit Reports". next to the GuestID field.

I have struggled with this and can't figure out what it is i'm doing wrong... code below:


Private Sub Form_GotFocus(value As Long)
'Shows comment next to GuestID

If GuestFirstName = John Then
If GuestLastName = Smith Then
lblTrip.Visible = True
Else
lblTrip.Visible = False
End If
End Sub

I've got the text listed as lblTrip set and ready to go. Like I said, i'm not that good with code so any help would be appreciated.

[noevil]

"Unless you try to do something beyond what you have already mastered, you will never grow." Ralph Waldo Emerson
 
John and Smith as you have them will be regarded as the names of variables ... not as text strings. Try something like
Code:
lblTrip.Visible = (GuestFirstName & GuestLastName = "JohnSmith")
 

I see a couple of problems

First, the header for the form's GotFocus event is

Private Sub Form_GotFocus()

not

Private Sub Form_GotFocus(value As Long)

you can't take a native Access sub and change it by adding your own argument.

Secondly, a form in Access never receives focus unless

1) There are no objects on the form that can receives

or

2) All objects that can receive focus are disabled

so even if the sub was headed correctly, the form is probably never going to receive focus to fire the code. I suspect moving it to the Form_Current event will do it:

Code:
Private Sub Form_Current()
If Me.GuestFirstName = "John" and Me.GuestLastName = "Smith" Then
  lblTrip.Visible = True
Else
  lblTrip.Visible = False
End If  
End Sub

You've given "John" and "Smith" here, but how/where are you getting the actual values you're comparing against the current record to decide whether to show your label?


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks so much it works great.you were correct about all comments. as i said, newbie learning to code and very much appreciate your assistance.

[noevil]

"Unless you try to do something beyond what you have already mastered, you will never grow." Ralph Waldo Emerson
 
Just a tip - Indent all your code as it would make it easier to see you hadn't closed an If statement

So
Code:
If GuestFirstName = John Then
If GuestLastName = Smith Then
      lblTrip.Visible = True
    Else
        lblTrip.Visible = False
End If
would become
Code:
If GuestFirstName = John Then
    If GuestLastName = Smith Then
       lblTrip.Visible = True
    Else
       lblTrip.Visible = False
    End If
[COLOR=red]End If[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top