Text box update with If..Then

  • Thread starter Thread starter maceslin
  • Start date Start date
M

maceslin

New to coding...

I want to use a selection in a combo box (cboClassification) to
populate a text box (Con_Num_Class) on the same form. The code I am
using is not working

Private Sub cboClassification_()
If cboClassification = "UNCLASS" Then
Me!Con_Num_Class = "U"
Else
If cboClassification = "CONFIDENTIAL" Then
Me!Con_Num_Class = "C"
Else
If cboClassification = "SECRET" Then
Me!Con_Num_Class = "S"
End If
End If
End If
End Sub

Any suggestions?

Dave
 
The problem I see is this:
Private Sub cboClassification_()
There is no event name here. Where are you expecting this to execute? I
would suspect it should be in the combo's After Update event.

Also, this is a good place to use a Select Case statememt:

With Me
Select Case .cboClassification
Case "UNCLASS"
.Con_Num_Class = "U"
Case "CONFIDENTIAL"
.Con_Num_Class = "C"
Case "SECRET"
.Con_Num_Class = "S"
End Select
End With
End If
End If
 
What event are you using? Should be the cboClassification's After Update
event. Also be sure in your code to preface cboClassification with Me:

If Me.cboClassification = "UNCLASS" Then
Me!Con_Num_Class = "U"
Else
If Me.cboClassification = "CONFIDENTIAL" Then
Me!Con_Num_Class = "C"
Else
If Me.cboClassification = "SECRET" Then
Me!Con_Num_Class = "S"
End If
End If
End If

Give that a try. Also might want to use a SELECT Case statement instead.
 
What does "not working" mean? Are you getting an error message? If so, what
is it? Or is it a case that nothing's going into the text box?

Are you certain that cboClassification returns what you think it does? Try
the following:

Private Sub cboClassification_()
Select Case Me!cboClassification
Case "UNCLASS"
Me!Con_Num_Class = "U"
Case "CONFIDENTIAL"
Me!Con_Num_Class = "C"
Case "SECRET"
Me!Con_Num_Class = "S"
Case Else
MsgBox "The combo box is returning " & _
Me!cboClassification
End Select
End Sub
 
Dave,
Try...
Private Sub cboClassification_AfterUpdate()
If cboClassification = "UNCLASS" Then
Me!Con_Num_Class = "U"
ElseIf cboClassification = "CONFIDENTIAL" Then
Me!Con_Num_Class = "C"
ElseIf cboClassification = "SECRET" Then
Me!Con_Num_Class = "S"
End If
End Sub

You could also use a Select Case Statement to accomplish the same thing.

BUT... all this is redundant. If cboClassification is bound to some
field in your table, (say Classification) that would be all you need to
capture. Having another control to capture the "U" in Unclass, or "C" in
Classified... etc, is redundant.
Given that you capture "UnClass, you could always calculate and display
the "U" (on the fly) by using an unbound text control with a Control Source
of ...
= Left(cboClassification, 1)
--
hth
Al Campagna
Access MVP 2007
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love, and you'll never work a day in your life."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top