Isnull Function for combo box

virencm

Registered User.
Local time
Today, 21:32
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
 
Try;
Code:
If Not IsNull(me.qengines.value) then
msgbox " Engine Exists!"
else
end if
 
What fails about the code you posted? You haven't actually described a problem anywhere.
 
it doesnt seem to like it.
i have got the focus set to combo box (qengines )before running the if statement.
 
hi lagbolt

When i hit the create button, if the combo box has any values it doesnt prompt with a msgbox.
 
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.
 
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:
 
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
 
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
 
.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
 
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)
 
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.
 
Glad you found a solution. There are often multiple solutions to any problem :)
 

Users who are viewing this thread

Back
Top Bottom