Nine message boxes

steve87bg

Registered User.
Local time
Today, 13:56
Joined
Jan 14, 2013
Messages
19
I have a code that wont work. If i click add button when all field are null then i see message box for first if function. Then if i fill the first field and left all other field null and click add button i dont see any message box and record is added to the tables. Anyone know why is this happening to me?
Is there a lot of message boxes?
:banghead::banghead::banghead:
Code:
Private Sub Add_Click()
If IsNull(Me.DatumKnjizenja) Then
MsgBox "Molim vas unesite DATUM.", vbInformation, "Greška"
Me.DatumKnjizenja.SetFocus
Exit Sub
Else
If IsNull(Me.Naziv) Then
MsgBox "Molim vas unesite NAZIV KOMITENTA.", vbInformation, "Greška"
Me.Naziv.SetFocus
Exit Sub
Else
If IsNull(Me.BrRacuna) Then
MsgBox "Molim vas unesite BROJ RACUNA.", vbInformation, "Greška"
Me.BrRacuna.SetFocus
Exit Sub
If IsNull(Me.DatumIzdavanja) Then
MsgBox "Molim vas unesite DATUM IZDAVANJA RACUNA.", vbInformation, "Greška"
Me.DatumIzdavanja.SetFocus
Exit Sub
Else
If IsNull(Me.PDVStopa) Then
MsgBox "Molim vas unesite PDV STOPU.", vbInformation, "Greška"
Me.PDVStopa.SetFocus
Exit Sub
Else
If IsNull(Me.IznosSaPDVom) Then
MsgBox "Molim vas unesite IZNOS RACUNA.", vbInformation, "Greška"
Me.IznosSaPDVom.SetFocus
Exit Sub
Else
If IsNull(Me.RokPlacanja) Then
MsgBox "Molim vas unesite ROK PLACANJA.", vbInformation, "Greška"
Me.RokPlacanja.SetFocus
Exit Sub
Else
If Me.txtDaNe = "DA" And IsNull(Me.txtRoba) Then
MsgBox "Molim vas unesite PRODAJNU VREDNOST ROBE.", vbInformation, "Greška"
Me.txtRoba.SetFocus
Exit Sub
Else
If Me.txtDaNe = "DA" And IsNull(Me.VrstaRobe) Then
MsgBox "Molim vas unesite VRSTU ROBE.", vbInformation, "Greška"
Me.VrstaRobe.SetFocus
Exit Sub
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If

....................
 
First, I would indent you IF statement and match up the END IFs. Second you only need one END SUB at the end of the routine. The ELSE statement should prevent the other IF from executing when that particular IF statement is TRUE.
 
Can you explain me by example what to do because i didnt understand you wery well. :(
 
Your If's are not structured correctly. They are like this:
Code:
If something
    Do something
Else
    If something2
        Do something2
    Else
        If something3
            Do something3
        End If
    End If
End If
And they should be:
Code:
If something
    Do something
End If
If something2
    Do something2
End If
If Something3
    Do Something3
End If
So as you can see, the first example shows a nested if where each If is dependent on the result of the If above it but in your case, there is no dependency so the If's should not be nested.
 
it might also be that you are testing for nulls, but in fact you have blank strings - which are blank but not null .... (zero length strings)
 

Users who are viewing this thread

Back
Top Bottom