Very Small Code Problem

ddrew

seasoned user
Local time
Today, 05:59
Joined
Jan 26, 2003
Messages
911
Im getting a compile error Else wihout If, its highlighting the Else that I have coloured red, Im sure its realm simple!

Code:
    If Me.chkboxRegistar = True Then
    If Me.txt_ContactsCount = "0" Then
        DoCmd.OpenForm "frm_Contacts", acNormal, "", "", , acNormal
        MsgBox "You dont have anyone in your Contacts," & vbCrLf & "Therefore you have been taken to the Contacts Form", vbOKOnly
    Else

        DoCmd.OpenForm "frm_SetUp", acNormal, "", "", , acNormal
        DoCmd.Close acForm, Me.Name
[COLOR="Red"]Else[/COLOR]
          MsgBox "You must first register the product", vbOKOnly
    End If
 
My guess is you need to put an End If statement after the nested one:

Code:
If Me.chkboxRegistar = True Then
 If Me.txt_ContactsCount = "0" Then
        DoCmd.OpenForm "frm_Contacts", acNormal, "", "", , acNormal
        MsgBox "You dont have anyone in your Contacts," & vbCrLf & "Therefore you have been taken to the Contacts Form", vbOKOnly
    Else
        DoCmd.OpenForm "frm_SetUp", acNormal, "", "", , acNormal
        DoCmd.Close acForm, Me.Name
    End If    
Else
          MsgBox "You must first register the product", vbOKOnly
End If
 
nested if's can get hard to follow.

because the regstration test is not really part of the the "real" test - I often use goto's to get what I want. also, proper indentation is helpful. in your original post, it was a bit difficult to see which if/else/end if matched together.

this sort of thing.

Code:
If not chkboxRegistar Then 
 MsgBox "You must first register the product", vbOKOnly
 exit sub
End If   
 
If Me.txt_ContactsCount = "0" Then
        DoCmd.OpenForm "frm_Contacts", acNormal, "", "", , acNormal
        MsgBox "You dont have anyone in your Contacts," & vbCrLf & "Therefore you have been taken to the Contacts Form", vbOKOnly
Else
        DoCmd.OpenForm "frm_SetUp", acNormal, "", "", , acNormal
        DoCmd.Close acForm, Me.Name
End If
 

Users who are viewing this thread

Back
Top Bottom