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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button -enable/disable status problem

Status
Not open for further replies.

pinstripe

Programmer
Dec 27, 2004
52
i have a listbox where is one column!
then i have button which has a status diabled
now with the code below i wanna to enable button if there is any data - it remains disabled if there is no data
but it is not working -- i have status in any case enabled or enabled- Why?

Private Sub Form_Load()

If IsNull(DLookup("[BOM Level]", "[BOM L2]", ("[BOM Level]= '" & Me.[List97].Column(0) & "'"))) Then
nextlevel.Enabled = False '' remains disabled
Else
nextlevel.Enabled = True
End If

End Sub
 
try a little debugging....like make the first line

msgbox DLookup("[BOM Level]", "[BOM L2]", ("[BOM Level]= '" & Me.[List97].Column(0) & "'"))

and see if it's giving the answer you expect (null or not null).

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
yes it give's me back "true"

but yet it is not working ??
 
what's it doing?


Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
what i did is :
MsgBox IsNull(DLookup("[BOM Level]", "[BOM L2]", ("[BOM Level]= '" & [Forms]![BOM L1]![List97].Column(0) & "'")))

it give's me "true" in any case even if it is not null)
i can't figure it out
 
sorry, what i have forget is ... the listbox [List97]is never selected !!!
that's why i get TRUE all the time

but how can i make this right inspite of selection of the listbox ?
thanks
 
put it instead in the AfterUpdate (or whichever works) event of the list box (instead of OnLoad of form).

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Or place it wherever you need, but test for selection first (btw when returning the bound column, you don't need reference through the .column property):

[tt]if me!List97.Listindex=-1 then
nextlevel.Enabled = False
else
nextlevel.Enabled = IsNull(DLookup("[BOM Level]", "[BOM L2]", "[BOM Level]= '" & Me.[List97] & "'"))
end if[/tt]

Roy-Vidar
 
How are ay RoyVidar . . . . .

Correct me if I'm wrong, but [purple]ListIndex[/purple] also returns [purple]-1[/purple] for a [blue]valid list[/blue] (records returned) but [purple]no selection yet made?[/purple]

or

You may have just meant to use the [purple]ListCount[/purple]:
Code:
[blue]if me!List97.[purple][b]ListCount[/b][/purple] = 0 then
  nextlevel.Enabled = False
else
  nextlevel.Enabled = IsNull(DLookup("[BOM Level]", "[BOM L2]", "[BOM Level]= '" & Me.[List97] & "'"))
end if[/blue]

Calvin.gif
See Ya! . . . . . .
 
Are my eyes deceiving me?

IsNull(
DLookup("[BOM Level]", "[BOM L2]",[COLOR=red yellow]([/color]"[BOM Level]= '" & Me.[List97].Column(0) & "'"[COLOR=red yellow])[/color]))

You have ...
("[BOM Level]= '" & Me.[List97].Column(0) & "'")
... enclosed in brackets
Which may be interpreted as True or False

So your DLookup will read as...
DLookup("[BOM Level]", "[BOM L2]", True)
...or
DLookup("[BOM Level]", "[BOM L2]", False)

Perhaps trying the code without the brackets around your conidtion / where clause...
DLookup("[BOM Level]", "[BOM L2]", "[BOM Level]= '" & Me.[List97].Column(0) & "'"))

You can also use DCount as follows...

Code:
Private Sub Form_Load()

If (DCount("[BOM Level]", "[BOM L2]", "[BOM Level]= '" & Me.[List97].Column(0) & "'")) Then
   nextlevel.Enabled = False '' remains disabled
Else
   nextlevel.Enabled = True
End If

End Sub

Here, instead of testing for Null / not found, Dcount will give you 0 or a number >0 which interpretted as false / true within the IF statement. (PHV taught me that one.)

And somebody already told you that the Form_Load event will occur once and there may be no records in the form. A way around this is to pass the value that will / may be in the List97 listbox as an OpenArgs from the calling form / program.

If this sounds like what you are looking for, use Help to find out about OpenArgs. Pretty easy -- part of the options when opening a form, and is referenced in the form as ... Me.OpenArgs

Richard
 
thank all of you for the help

all of your tips were helpfull
but i have finished with this code :

Private Sub Form_Load()
Dim x As Integer
x = 1

If IsNull(DLookup("[BOM Level]", "[BOM L2]", ("[BOM Level]= '" & [Forms]![BOM L1]![List97].Column(0, x) & "'"))) Then

nextlevel.Enabled = False
Else

nextlevel.Enabled = True

End If

End Sub


first i had also a loop ... for x... but it turned out that even that was not necesary

thank's again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top