Isnull Function for combo box (1 Viewer)

virencm

Registered User.
Local time
Today, 14:05
Joined
Nov 13, 2009
Messages
61
Hi guys

Need help with an isnull function for a combo box.

Combo box name : Qengines

Record source for qengines is a query with criteria set to a value on the same form.

When i hit command button (Create) on the form i want the combo box to check for null values. if it has values then msgbox " Engine Exists !"

I have tried to use
Code:
if isnull(me.qengines.value) = false then
msgbox " Engine Exists!"
else
endif

Please help !

Cheers
 

John Big Booty

AWF VIP
Local time
Today, 14:05
Joined
Aug 29, 2005
Messages
8,263
Try;
Code:
If Not IsNull(me.qengines.value) then
msgbox " Engine Exists!"
else
end if
 

MarkK

bit cruncher
Local time
Yesterday, 21:05
Joined
Mar 17, 2004
Messages
8,181
What fails about the code you posted? You haven't actually described a problem anywhere.
 

virencm

Registered User.
Local time
Today, 14:05
Joined
Nov 13, 2009
Messages
61
it doesnt seem to like it.
i have got the focus set to combo box (qengines )before running the if statement.
 

virencm

Registered User.
Local time
Today, 14:05
Joined
Nov 13, 2009
Messages
61
hi lagbolt

When i hit the create button, if the combo box has any values it doesnt prompt with a msgbox.
 

MarkK

bit cruncher
Local time
Yesterday, 21:05
Joined
Mar 17, 2004
Messages
8,181
Are you sure the code runs? What happens if you do this?
Code:
MsgBox "This code runs for sure!!!"
If Not IsNull(Me.qengines) Then
  MsgBox "Engine Exists!"
End If
Do you get the first msgbox? Sometimes an active error handler or other process unexpectedly diverts your code before it does what you expect. If you do get the msgbox, please post the whole procedure, not just this little fragment.
 

John Big Booty

AWF VIP
Local time
Today, 14:05
Joined
Aug 29, 2005
Messages
8,263
I'm starting to wonder if this is the right approach to the problem. Perhaps a DCount() against the engine value would be a better approach :confused:
 

John Big Booty

AWF VIP
Local time
Today, 14:05
Joined
Aug 29, 2005
Messages
8,263
The code might also work better if it looked like;
Code:
If Not IsNull(Me.qengines) or Me.qengines <>0 Then
  MsgBox "Engine Exists!"
End If
 

virencm

Registered User.
Local time
Today, 14:05
Joined
Nov 13, 2009
Messages
61
Hi john Big Booty

How does the dcount() function work? could you please send me an example.
I m going to try the latest code you posted. i'll let you know if it works.

cheers for your quick response
 

CBrighton

Surfing while working...
Local time
Today, 05:05
Joined
Nov 9, 2010
Messages
1,012
.Value on a combobox should give you the contents of the bound column of the currently selected record.

If the row source is a query but you are not selecting something from the dropdown box then I would expect the value to always be null.

I would use DCount() or put some VBA with a recordset & .RecordCount behind the command button to check the number of records in the query.



DCount():

The syntax for the DCount function is:
DCount ( expression, domain, [criteria] )

Let's take a look at a simple example:
DCount("UnitPrice", "Order Details", "OrderID = 10248")
In this example, you would return the number of records in the Order Details table where the OrderID is 10248. This is the same as the following SQL statement:
SELECT Count([Order Details].UnitPrice) AS CountOfUnitPrice
FROM [Order Details]
WHERE ((([Order Details].OrderID)=10248));


Source: http://www.techonthenet.com/access/functions/domain/dcount.php
 

John Big Booty

AWF VIP
Local time
Today, 14:05
Joined
Aug 29, 2005
Messages
8,263
Hi john Big Booty

How does the dcount() function work?

...
The link my post #7 has a pretty good explanation of what it does and how it works. You can refrence a form control if you structure it like;
Code:
DCount("FieldToCount", "TBL_ToSearch", "FieldToMatchOn = " & Me.FieldOnFormWithCriteria)
 

virencm

Registered User.
Local time
Today, 14:05
Joined
Nov 13, 2009
Messages
61
Hi John

The Dcount didnt work. but i tried .listcount and that works perfectly

if me.qengines.listcount <>0 then
msgbox " Engine Exists!"
else
end if


thank you for all your help.
 

John Big Booty

AWF VIP
Local time
Today, 14:05
Joined
Aug 29, 2005
Messages
8,263
Glad you found a solution. There are often multiple solutions to any problem :)
 

Users who are viewing this thread

Top Bottom