If statement/msgbox coding problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having a small problem getting a msgbox to pop up on a form when the user
enters a number larger than a number stored in a related table. Here's the
code for the after update of the text box on the form:

Private Sub LeafLbs1_AfterUpdate()
If Me.LeafLbs1.Value > Me.Equipment.Column(3).Value Then
MsgBox "Wrong"
Cancel = True
End If
End Sub

The form (called dailyreport) is based on a master table of information.
There is another table, vehicles, linked to this table, which stores
information on the different vehicles that are used. I want a warning message
to come up if the user enters a vehicle weight that is higher than the
maximum weight stored in the vehicles table.
In the above vb code, i used Equipment.Column(3) because earlier on this
same form, the user has already entered the vehicle number in a text box
called Equipment. Since I figured this box is linked to the vehicles table, I
could simply call the number this way. Apparently not, since I can't seem to
get it to work.

Any ideas? I can provide more info if needed.
 
I'm having a small problem getting a msgbox to pop up on a form when the user
enters a number larger than a number stored in a related table. Here's the
code for the after update of the text box on the form:

Private Sub LeafLbs1_AfterUpdate()
If Me.LeafLbs1.Value > Me.Equipment.Column(3).Value Then
MsgBox "Wrong"
Cancel = True
End If
End Sub

The form (called dailyreport) is based on a master table of information.
There is another table, vehicles, linked to this table, which stores
information on the different vehicles that are used. I want a warning message
to come up if the user enters a vehicle weight that is higher than the
maximum weight stored in the vehicles table.
In the above vb code, i used Equipment.Column(3) because earlier on this
same form, the user has already entered the vehicle number in a text box
called Equipment. Since I figured this box is linked to the vehicles table, I
could simply call the number this way. Apparently not, since I can't seem to
get it to work.

Any ideas? I can provide more info if needed.

The AfterUpdate event does not have a Cancel argument.
You would need to use the control's BeforeUpdate event.

Just to make sure I understand your set-up...
Equipment is a combo box on this form.
The combo box column you wish to refer to is the 4th column in this
combo box (Combo's are Zero based, so Column(3) is the 4th column).
Adjust your code if it is not the 4th column.

Private Sub LeafLbs1_BeforeUpdate(Cancel as Integer)
If Me!LeafLbs1 > Me!Equipment.Column(3) Then
MsgBox "Wrong"
Cancel = True
End If
End Sub
 
Fred,
Thanks for the help but with the no code nothing happens. I'm aware of the
zero-column rule, and I'll try to clarify my situation a little. Equipment is
a combo box that is linked to another table. The 4th column of the table
contains the maximum weight for each vehicle (or equipment). I want an error
message if the user enters a value in the text box LeafLbs1 that is higher
than the corresponding vehicle's maximum weight (they entered the vehicle
number earlier, using the Equipment combo box).

I would assume I need an after update code, so that the code is applied
after the user has entered a number. Thanks for the help, let me know if you
need more info.
 
Fred,
Thanks for the help but with the no code nothing happens. I'm aware of the
zero-column rule, and I'll try to clarify my situation a little. Equipment is
a combo box that is linked to another table. The 4th column of the table
contains the maximum weight for each vehicle (or equipment). I want an error
message if the user enters a value in the text box LeafLbs1 that is higher
than the corresponding vehicle's maximum weight (they entered the vehicle
number earlier, using the Equipment combo box).

I would assume I need an after update code, so that the code is applied
after the user has entered a number. Thanks for the help, let me know if you
need more info.
 
What's the RowSourcefor the Equipment combo? Are you retrieving all of the
fields of this table? In other words, is Column(3) referring to something
that you have in your control source or is it simply that exists as a field
in the table?

What is the value of the Column Count property?

Let us know!
 
The rowsource is a column0 of the linked table. There are about 10 choices
that have already been written into another table, and user selects one from
the list. Column3 is the corresponding maximum weight of that choice. Hope
this helps, I really want to figure this out! Let me know if more info is
needed.
 
Back
Top