Results 1 to 3 of 3

Thread: Code Help

  1. #1
    Join Date
    Sep 2015
    Posts
    1

    Unanswered: Code Help

    I am setting a database in Access for a colleague and struggling with the code. Am new to this and have managed some basic code but am getting an error with this one. I am trying to get it so certain fields only show dependent on the option selected in another.
    The error message I am getting is 'Compile Error: Block If without End If' Is anyone able to advise.
    Thanks
    Nikki

    Code:
    Private Sub EnrolmentStatus_AfterUpdate()
    If Me.EnrolmentStatus = Active Then
    Me.EnrolmentWithdrawalDate.Visible = True And Me.EnrolmentWithdrawalReason.Visible = True And Me.EnrolmentAchievedDate.Visible = True And Me.EnrolmentCertificationDate.Visible = True
    Else
    If Me.EnrolmentStatus = Achieved Then
    Me.EnrolmentWithdrawalDate.Visible = True And Me.EnrolmentWithdrawalReason.Visible = True And Me.EnrolmentAchievedDate.Visible = False And Me.EnrolmentCertificationDate.Visible = False
    Else
    If Me.EnrolmentStatus = Withdrawn Then
    Me.EnrolmentWithdrawalDate.Visible = False And Me.EnrolmentWithdrawalReason.Visible = False And Me.EnrolmentAchievedDate.Visible = True And Me.EnrolmentCertificationDate.Visible = True
    Else
    If Me.EnrolmentStatus = "On Hold" Then
    Me.EnrolmentWithdrawalDate.Visible = True And Me.EnrolmentWithdrawalReason.Visible = True And Me.EnrolmentAchievedDate.Visible = True And Me.EnrolmentCertificationDate.Visible = True
    End If
    End Sub

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    that error tell you need the some End If
    or make them elseif

    rules are

    if something then


    End if

    or

    if something then

    elseif then

    End if

    but

    if something then dothis if the if then somethingon 1 line don't need the end if

    you dont need the end if


    a good habbit

    write the

    if then

    else

    end if

    them arrow back and full in the missing bits
    I always put the else in even if you don't use it
    just make it easier when you have if in side if in side if
    Last edited by myle; 09-16-15 at 16:00. Reason: Spelling
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    496
    Provided Answers: 24
    1. your Enrolment status propably want to check a string,"Achieved"
    2. you cant AND settings/assignments ...separate them.
    3. use a CASE statement if you have lost of IFs

    Code:
    Select Case Me.EnrolmentStatus
      Case "Active"
         Me.EnrolmentWithdrawalDate.Visible = True
         Me.EnrolmentWithdrawalReason.Visible = True
         Me.EnrolmentAchievedDate.Visible = True
         Me.EnrolmentCertificationDate.Visible = True
      Case "Achieved"
         Me.EnrolmentWithdrawalDate.Visible = True
         Me.EnrolmentWithdrawalReason.Visible = True
         Me.EnrolmentAchievedDate.Visible = False
         Me.EnrolmentCertificationDate.Visible = False
      Case "Withdrawn"
         Me.EnrolmentWithdrawalDate.Visible = False
         Me.EnrolmentWithdrawalReason.Visible = False
         Me.EnrolmentAchievedDate.Visible = True
         Me.EnrolmentCertificationDate.Visible = True
      Case "On Hold"
         Me.EnrolmentWithdrawalDate.Visible = True
         Me.EnrolmentWithdrawalReason.Visible = True
         Me.EnrolmentAchievedDate.Visible = True
         Me.EnrolmentCertificationDate.Visible = True
    End Select

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •