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!

Isnull flexibility 2

Status
Not open for further replies.

Akart

IS-IT--Management
Nov 14, 2002
71
AU
Hey there,

Surely this has a simple answer:

This bit works:

If Not IsNull(Forms!Customers_Main_Au!Customers_Search_AU.Form.CustomerId) then
msgbox "Has Value"
End If

Returns "Has Value"

What i want to do is replace CustomerID with any field name like this
dim tempfield
tempfield = "CustomerID"

If Not IsNull(Forms!Customers_Main_Au!Customers_Search_AU.Form.tempfield) then
msgbox "Has Value"
End If


This method does not work. Help!

Any suggestions appreciated!

Kerrin
 
Try

If Not IsNull(Forms!Customers_Main_Au!Customers_Search_AU(tempfield)) then
msgbox "Has Value"
End If

Good luck [pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Wouldn't having a function being passed a control returning a boolean be better?

Craig
 
Thanks danvlas, this method worked for me.


If Not IsNull(Forms!Customers_Main_Au!Customers_Search_AU(tempfield)) then
msgbox "Has Value"
End If


Craig0201,
you mentioned a FUNCTION would be better. Do you have an example FUNCTION that would make my code better.

Regards,

Kerrin
 
You function would look something like this:

Function ControlHasValue(tempField As Control) As Boolean

If (IsNull(tempField)) Then
ControlHasValue= False
Else
ControlHasValue= True
End If

End Function

Here's an example of calling it via the BeforeUpdate event of a text box (CustomorID).

Private Sub CustomorID_BeforeUpdate(Cancel As Integer)

If (ControlHasValue(CustomorID)) Then
MsgBox "has value"
Else
MsgBox "has no value"
Cancel = true
End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top