Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form_Open event problem

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hi

How to check if there are values in the listbox of the form, so that if there are no values, then not to open form at all.

Thanks


 
if me!lstbox = null then
cancel = true
end if

if me!lstbox2 = null then
cancel = true
end if

this type of code needs to be put in the on open event of the form...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
are you sure it was in the on open, and not in the on load??

also, what vertion of access are you using??

hmm... and you made the names of the control's the same as what you have them on the form??

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Here's a bit of a different approach,which may work for you.

If IsNull(Me.Listbox.Column(0, 0)) Then
DoCmd.Close acForm, "Form1"
End If

David I'm Your Huckleberry!
 
I use Access 97

All the names are fine
The thing is my IF statement doesn't seem to be working

If List.column (0,0) = null then
do something
else
do something
end if

Well, even though List.column(0,0) = null, it jumps to ELSE

WHY?
 
Paste your code in a post so we can see it.

David I'm Your Huckleberry!
 
Try

Sub Form_Open(Cancel As Integer)
If lstbox.ListCount = 0 Then
Cancel = True
End If
End Sub

Dan
[pipe]
 
Can I ask you a stupid question?

The code you pasted is referring to a control called
"lstbox".

If this is copied from a form directly, it should be ...
Me.lstbox or Me!lstbox.

Try replacing your code with this.
Replace it exactly.

If Me.lstbox.ListCount = 0 Then
Cancel = True
End If

David
I'm Your Huckleberry!
 
dpimental, and all the others...thanks a lot, it finally worked.
I appreciate your help
 
David...You're right.
But...I'm also right.

It's true that you can refer to a control on the form (from the form module) using the Me keyword.
But it's not necessary. There is absolutely no difference in the behaviour.
The same happens with methods:
Me.Requery has the same effect as Requery.

not to mention properties:

Me.Caption returns or sets the same thing as plain Caption

I only use Me when I am too lazy to type the next word (as typing the dot after Me expands the list :)

And when I want to refer to a control by a string variable like:

Me(NameFromATextBox)

Regards,
Dan
[pipe]
 
Dan, you're right, I don't know what I was thinking.

Regards,

David I'm Your Huckleberry!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top