Attention: Bruce M

R

Russ

You gave me some advice a few days ago about control Null values and
so forth. (See GoToControl macro action) Here is the code you
supplied:
In the form's Before Update event:

If IsNull(Me.Control_1) Then
MsgBox "Control_1 needs a value"
Me.Control_1.SetFocus
Cancel = True
ElseIf IsNull(Me.Control_2) Then
MsgBox "Control_2 needs a value"
Me.Control_2.SetFocus
Cancel = True
ElseIf IsNull(Me.Control_3) Then
MsgBox "Control_3 needs a value"
Me.Control_3.SetFocus
Cancel = True
End If


All was well, until I changed the Control Source property of one of
the combo box controls. Instead of it being Area, I changed it to
AreaID so the form would save the correct data. Then when I run the
form and insert a new record, I fill in the Area control via the combo
box and when I attempt to leave the form the code pops the message box
up telling me that AreaID control does not have a value. So, in the
code I changed the line:
IsNull(Me.Area) Then to
If IsNull(Me.AreaID) Then


As a result of that change, the Debug/Compile responds with: "Method
or Data Member not found".

How am I screwing up? Isn't the control source property what the code
(Me.AreaID) is looking for?
 
M

Maurice

Russ,

you should use the controlname of the control to which you are referring. If
the name of the control hasn't changed the code should still work. I think
reading your post you should be referring to your combobox name.
 
R

Russ

Well, I looked at the other controls that I'm also checking with this
code, and I do not have the control name in that line of code only the
control source as below:

Here is the code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.E58No) Then
MsgBox "E58 Number needs a value"
Me.E58No.SetFocus
Cancel = True
ElseIf IsNull(Me.OrigBy) Then
MsgBox "Originated By is blank"
Me.ComboOrigBy.SetFocus
Cancel = True
'The combo box OrigBy is named ComboOrigBy The control source is OrigBy

ElseIf IsNull(Me.Date) Then
MsgBox "Date needs to be filled in"
Me.Date.SetFocus
Cancel = True
ElseIf IsNull(Me.Area) Then
MsgBox "Must have an Area assigned"
Me.ComboArea.SetFocus
Cancel = True
End If
End Sub
 
R

Russ

Figure it out.

I changed the control source property to the control name as you
suggested, and things ran just fine. The other Combobox is not named
the same way and it also works. Go figure.
 

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

Top