Results 1 to 5 of 5
  1. #1
    netia1128 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Posts
    2

    Post VBA Error - End If Without If Block on multi-line If statement

    I know this is rather basic, but I am trying to run some VBA Code to do the following:



    If X Then
    action 1
    action 2
    action 3
    End If

    My issue is that when I run my code it kicks back an error for "End If Without If Block". For the meantime I can throw the If clause in before each action, but ultimately I would like to make this work where there is one If and then multiple subsequent actions. Depite a few hours of googling, I still can't pinpoint my exact problem. Any thoughts on what I may be doing wrong?

    The actual line of code I am running is here:

    If NLG_UR_AddBasicFacilityInfo = -1 Then _
    Do Cmd.OpenFor "NLG_Update_Basic_Facility_Info_Table", acFormAdd
    [Forms]![NLG_Update_Basic_Facility_Info_Table]![txt_NLG_UBFIR_FacilityID].Value = NLG_UR_FacilityID
    [Forms]![NLG_Update_Basic_Facility_Info_Table]![txt_NLG_UBFIR_UpdateDate].Value = NLG_UR_UpdateDate
    [Forms]![NLG_Update_Basic_Facility_Info_Table]![hdr_NLG_UBFIR].Value = "Update Basic Facility Info for " _
    & NLG_UR_StreetNo & " " & NLG_UR_Predirection & " " & NLG_UR_StreetName & " " & NLG)UR_StreetType & " " & NLG_UR_Unit
    End If

    I'm building my database on top of Access 2007 at the moment on a Window 7 PC. Please let me know if there is any further info I can provide.

    Thanks!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Start counting your If's and match them with an End If. Also, look for code outside of a sub Procedure (check for End Sub, etc.)

    EDIT: Never mind, you have a line continuation here

    Then _

    Try
    Then

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    In addition to ItsMe's advice, I assume that

    DoCmd.OpenFor

    is supposed to be

    DoCmd.OpenForm

    Also,

    NLG)UR_StreetType

    should be

    NLG_UR_StreetType

    Also, I'm assuming that you used a Wizard to create your Form and that

    "NLG_Update_Basic_Facility_Info_Table"

    actually is a Form, which is why its name sounds as if it were a Table name! Never have understood why the Wizards of Redmond chose to let this happen; having Table and Form with identical names is confusing, to say the least!

    Welcome to AFN!

    Linq ;0)>

  4. #4
    netia1128 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Posts
    2
    ItsMe and MissingLinq - thank you both for your advice! Taking the underscore off of the end of my THEN statement fixed the issue. Also, I've taken your advice to heart to not name forms and tables exactly the same. Much better (and actually functioning) script now. I appreciate the help!

    Netia

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2013 - Multi Line Textbox
    By mrmims in forum Forms
    Replies: 1
    Last Post: 10-06-2014, 05:57 PM
  2. INSERT INTO from multi line text box
    By Only4Access in forum Forms
    Replies: 3
    Last Post: 01-08-2014, 08:06 PM
  3. Complie error "End If without Block If
    By justair07 in forum Access
    Replies: 8
    Last Post: 12-13-2013, 09:03 AM
  4. Replies: 2
    Last Post: 05-22-2012, 03:29 PM
  5. Querying Multi Line Text Box in MS Access Forms
    By spindlebeakin10 in forum Queries
    Replies: 5
    Last Post: 12-09-2010, 05:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums