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

multiple if statements. 1

Status
Not open for further replies.

benzan

Technical User
Aug 29, 2007
20
US
my codings gotten little too complicated...

i don't get why the first if statement is not working..
it seems like other ones are looping fine...

Private Sub chkActual_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lresponse As Integer

DoCmd.RunCommand acCmdSaveRecord

If Me.BudgetKey = Null Then
MsgBox "you must approve your requisition before you can select an actual amount"
Me.chkActual = False
Me.chkEST = True
Exit Sub
'above line is not working..

End If

If Me.chkActual = True Then
Me.chkEST = False

lresponse = MsgBox("Have you entered the actual amount?", vbYesNo, "Continue")

If lresponse = vbYes Then
'only one check box available
Me.chkActual = True

Set db = CurrentDb()
Set rs = db.OpenRecordset("tbl_vregister", dbOpenDynaset)
rs.AddNew
rs![PrNum] = Me![txtPR]
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
DoCmd.SetWarnings False
DoCmd.OpenQuery "uQry_PRtoVR"
DoCmd.SetWarnings True
Me.chkEST = False

End If

If lresponse = vbNo Then
Me.Amount.SetFocus
Me.chkActual = False
Me.chkEST = True

End If
End If

End Sub


so the system is suppose to check and see if there is a value in "me.budgetkey" field box. If null then they can not proceed. If budgetkey is already assigned (dlookup on page load), then rs.edit

i know i have very bad codings but.. what am i doing wrong?
 
If you are sure that Null is the only thing you wish to test:

[tt]If IsNull(Me.BudgetKey) Then[/tt]
 
The reason why you have to use the isNull function is that checking for null on either side of your comparison will always return Null and therefore the if check will never be true.

Code:
Public Sub testNull()
  Dim x As Variant
  x = Null
  Debug.Print (x = 1)
  Debug.Print (x = Null)
  Debug.Print Not (x = Null)
  x = 1
  Debug.Print (x = 1)
  Debug.Print (x = Null)
  Debug.Print Not (x = Null)
End Sub
Results are:

Null
Null
Null

True
Null
Null

A more robust check is
if trim (yourControl.value & " ") = "" then
This will check for:
Null
empty string ""
blank space/s " "
empty value
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top