Code not working (?) - need help!!!

MeisterGirl

Registered User.
Local time
Today, 11:47
Joined
Aug 8, 2001
Messages
11
I have the following lines of code written behind my form:

If Prod_Grp = "EA" Then
Serv_Cd = "STD"
End If

If Prod_Grp = "IN" Then
Serv_Cd = "800"
End If

If Prod_Grp = "HD" Then
Serv_Cd = "HMD"
End If

If Prod_Grp = "TR" Then
Serv_Cd = "TRD"
End If

The problem is that when I enter the value for Prod_Grp, the Serv_Cd field is not populating. I have tried placing this code in several places in my form. Why is it not updating? Does the code need to be build behind Prod_Grp or behind Serv_Cd and does it need to run On Exit, On Update or what. Once again I will stress that I am not a coder at all so any help is appreciated!!!

Thanks!
 
I would use a Select Case statement instead of all those If statements.

Use the After Update event of the control "Prod_Grp" to do what you need.

Private Sub Prod_Grp_AfterUpdate()
Select Case Me.Prod_Grp
Case "EA"
Me.Serv_Cd = "STD"
Case "IN"
Me.Serv_Cd = "800"
Case "HD"
Me.Serv_Cd = "HMD"
Case "TR"
Me.Serv_Cd = "TRD"
End Select
End Sub

If this form is to be used to view already existing data, you will need to "Call" the Sub routine using the On Current event of the form to make the control populate when the form opens and as you navigate through each record. Here is how to "Call" the Sub.

Use the Form's On Current event:

Private Sub Form_Current()
Call Prod_Grp_AfterUpdate
End Sub

HTH
RDH

[This message has been edited by R. Hicks (edited 08-16-2001).]
 
This is a variation on your code and has an advantage over the If Then statments, but we will leave that for later... Put this code in the After Update event of your Prod_Gp text box:

Select Case Me![Prod_Grp]

Case "EA"
Me![Serv_Cd] = "STD"

Case "IN"
Me![Serv_Cd] = "800"

Case "HD"
Me![Serv_Cd] = "HMD"

Case "TR"
Me![Serv_Cd] = "TRD"

End Select
 
Worked Beautifully!!! Thanks Guys!! Pretty soon I'm going to have to start buying drinks for you guys!!!
 
Well - Stay thirsty because I have more questions to throw out there before Happy Hour!!!
If I knew the proper syntax and word use I wouldn't have such a problem becasue I understand the logic - it's just writing it down!!!
Anyway - thanks for all your help - I'll probably be hearing from you again soon!

Amy
 
Okay - who's ready for the next dumb question from the MeisterGirl??? Remember there are several Happy Hour drinks up for grabs!!

Here goes:
I have a filed called Prod_Grp and depending on what the user selects from the look up box I want o set requirements for three other fields. Example:
If Prod_Grp = EA then I want to set the Rel_TR and the Rel_IN fields to be required but allow them to skip Rel_OP.

And if Prod_Grp = TR then they skip the Rel_TR fields but the the Rel_IN and the Rel_OP fileds are required

And if Prod_Grp = IN or HD then they can skip Rel_IN but are required to populate Rel_OP and Rel_TR.

I know this is another easy one but give me break - I don't know the language!! Thanks again everyone - hope to hear from some one soon!!
 
Put the code to accomplish all this in the form's BeforeUpdate event procedure, something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Select Case Prod_Grp
Case "EA"
If IsNull(Rel_TR) Then
Cancel = True
Rel_TR.SetFocus
Exit Sub
End If
If IsNull(Rel_IN) Then
Cancel = True
Rel_IN.SetFocus
Exit Sub
End If
Case "TR"
'similar code
Case "IN", "HD"
'similar code
End Select
End Sub


[This message has been edited by AlanS (edited 08-20-2001).]
 
Awesome - I'm actually learning things - I changed my mind on how to use that function and placed it elsewhere in my form and even added a message for my user - there is hope for me yet!!!

Don't worry - I'll have more questions!!! Try not to miss me too much!! Talk to everyone soon!
 

Users who are viewing this thread

Back
Top Bottom