Combo Box NULL Values

bbagini

Registered User.
Local time
Yesterday, 16:39
Joined
Mar 8, 2012
Messages
10
hi i am trying to figure out some issues to do with null values of combo boxes for my db. Ive run through multiple different pages and used varying solutions to check for a null value of my combo boxes (ie nothing selected), all failing miserably for me so im thinking there may be an issue with my implimentation or my code in general.
My aim is to check the field qualid,
if it is null have the msgbox pop up saying
New qualification will not be saved due to incomplete recordsNAME. Would you like to proceed?", the yes/no functions leading to two different options
If qualid is not null then check the other fields too, there are 5 fields total. datetype has a default value hence doesnt need to be checked, 1 is a date field(date), 2 combo boxes (qualid, staffid), and a hyperlinked field(trainingrecord).
Any assistance in figuring out my problem/helping correct it would be much apprieciated as ive been scratching my head over this for the few days.


Code:
If IsNull(Me.staffid) Then
     If MsgBox("New qualification will not be saved due to incomplete recordsNAME. Would you like to proceed?", vbYesNo) = vbYes Then
          Me.Undo
          MsgBox "Record was not saved", vbOKOnly
          DoCmd.Close
     Else
          MsgBox "Please select a staff name"
          End If
Else
          If IsNull(Me.qualid) Then
               If MsgBox("New qualification will not be saved due to incomplete recordsQUAL.      Would you like to proceed?", vbYesNo) = vbYes Then
                    Me.Undo
                    MsgBox "Record was not saved", vbOKOnly
                    DoCmd.Close
               Else
                    MsgBox "Please select a qualification"
                    End If
          Else
               If IsNull(Me.date) Then
                    If MsgBox("New qualification will not be saved due to incomplete recordsDATE. Would you like to proceed?", vbYesNo) = vbYes Then
                         Me.Undo
                         MsgBox "Record was not saved", vbOKOnly
                         DoCmd.Close
                    Else
                         MsgBox "Please select a date"
                    End If
               Else
                    If Nz(trainingrecord, "n/a") = "n/a" Then
                         If MsgBox("New qualification will not be saved due to incomplete recordsCERT. Would you like to proceed?", vbYesNo) = vbYes Then
                              Me.Undo
                              MsgBox "Record was not saved", vbOKOnly
                              DoCmd.Close
                         Else
                              MsgBox "Please attatch a training certificate"
                         End If
                    Else
                         DoCmd.Close
 
                    End If
               End If
          End If
     End If
 
Last edited:
I gave up trying to read your code because of the lack of indentation.

However, get into the habit of testing for null and zero-length strings in one:

If Nz(Text1,"") = "" Then

Only use IsNull() when you want to treat it separately to "" (very rarely).
 
Editted code for indenting, it just copied horribly, didnt notice sorry. Ive tried If Nz(qualid, "") ="" then and it came up with the same issues im having.
The main issues are with the qualid/staffid as in the code i did manage to get Nz(trainingrecord, "n/a") = "n/a" working fine
 
Last edited:
managed to get it working using staffid = 0, was making the mistake due to it actually being linked to an id field but displaying names. I still used Nz() = "" for theother fields so that ended up helping, so thanks.
 
Yeah I should have said, for testing numeric fields: Nz(field,0) = 0 or Nz(field,-1) = -1

One observation: Having a field called Date will cause you problems. Try not to name fields with words that have other meanings in VBA.
 

Users who are viewing this thread

Back
Top Bottom