List Box

D

Dickbee

I want to ensure that when people exit a form that in certain list boxes
information must be entered is there are simple way to do this.

Thanks
 
F

fredg

I want to ensure that when people exit a form that in certain list boxes
information must be entered is there are simple way to do this.

Thanks

Code the Form's Unload event:

If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = true
Me![ControlName].SetFocus
End if
 
L

Linq Adams via AccessMonster.com

Exactly how are you entering data in these "listboxes?" Listboxes are
designed to make data selections from, not to enter data into.
 
A

Author

Could be a listbox where null is not an option.
Anyone got change for a nickel? Cause that's just my two cents.
 
D

Dickbee

I have no idea about code do I just copy in what you have put there or is
there more to it. Or am I wasting my time because I don't know how to use
code. Are the books you can get that will help me right code.

Thanks

fredg said:
I want to ensure that when people exit a form that in certain list boxes
information must be entered is there are simple way to do this.

Thanks

Code the Form's Unload event:

If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = true
Me![ControlName].SetFocus
End if
 
D

Dickbee

Can i appoligise and say that it is a combo box not a list box does this
change everything. Sorry Still learning this stuff
 
F

fredg

I have no idea about code do I just copy in what you have put there or is
there more to it. Or am I wasting my time because I don't know how to use
code. Are the books you can get that will help me right code.

Thanks

fredg said:
I want to ensure that when people exit a form that in certain list boxes
information must be entered is there are simple way to do this.

Thanks

Code the Form's Unload event:

If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = true
Me![ControlName].SetFocus
End if

Display the Form's property sheet.
Click on the Event tab.
Click on the event line you wish to code (the Unload event line).
Write
[Event Procedure]
on that line.
Then click on the little button with the 3 dots that appears on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those lines write this code.

If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = true
Me![ControlName].SetFocus
End if

You can either copy and paste the above code, or just write it.
Change [ControlName] to whatever the actual name of the control is you
wish to check for Null.
And no, it doesn't matter if it is a List Box or a Combo box.
 
L

Linq Adams via AccessMonster.com

This only makes sense if your combobox is bound to a field in the underlying
table. You can check this, in Design View, if you're uncertain, by selecting
the combobox, then going to Properties - Data and seeing if there's a field
name listed in the Control Source Property.

If the combobox is, indeed, bound, then Fred's code will do the trick. You
should, however, probably place it in the form's BeforeUpdate event. This way,
it will also warn the user if they simply try to move to another record or
enter another new record, as well as if they try to close the form, with the
field in question empty.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([ControlName]) Then
MsgBox "You must enter data."
Cancel = True
Me![ControlName].SetFocus
End If
End Sub

Copy the code

From Design View, hit >Control> + <G> to go to the code window

Directly below the line

Option Compare Database

paste the code. Now simply replace ***ControlName*** in the code with the
actual name of your combobox. You should now be set.


Simply replace ControlName with the actual name of your combobox.
 
Top