Results 1 to 7 of 7
  1. #1
    LOUISBUHAGIAR54 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Malta
    Posts
    3

    Unhappy Do loop while not working within mulitple if, else end if conditions.

    I am a self taught Access User. This is the first time I am requesting help in access forums. I am trying to use a do... loop while cycler within multiple if else endif conditions. This is the first time I have used a do while loop cycler and I have never had any problems. This time it is not working and the message is ' 'Loop without Do'.



    I really can't figure out what is tripping this program. To clarify the issue I am sending a sample of the program, which is much longer. Many thanks for your help. Can anyone assist please ?

    The following is the code.


    ElseIf Me.Frame53 = 1 Then 'if patient is hospitalised
    Dim admixxin As Date
    Dim licenzjat As String
    Dim hstay As Integer
    Dim tothstay As Integer
    Dim numru As Integer

    Do

    admixxin = InputBox("Add the date of admission to hospital!", "Admitted to Hospital", , 3000, 3000)

    If StrPtr(admixxin) = 0 Then
    MsgBox "You have pressed cancel and the command will stop here!!!"
    Exit Sub
    End If
    ' the above sequence is in place so that if no admission date is available the command will stop here.

    licenzjat = InputBox("Add the date of discharge from Hospital", "Discharged from Hospital", "", 9000, 3000)
    sameta = ahhartaxahar
    If IsDate(licenzjat) = False Then
    If admixxin >= tibda Then
    hstay = ahhartaxahar - admixxin 'patient still in hospital by end of month.
    ElseIf admixxin < tibda Then
    hstay = ahhartaxahar - tibda + 1 ' patient in hospital throughout the month
    End If
    Else
    If admixxin >= tibda And CDate(licenzjat) <= ahhartaxahar Then
    hstay = CDate(licenzjat) - admixxin - 1
    ElseIf admixxin < tibda And CDate(licenzjat) <= ahhartaxahar Then
    hstay = CDate(licenzjat) - tibda

    End If

    messagg = MsgBox("Was the resident admitted to hospital again?", vbYesNoCancel, "Hospital admission no " & numru)
    tothstay = tothstay + hstay
    numru = numru + 1
    Loop While message = vbYes

    L. Buh

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The error is a bit misleading. Your If/Then clauses aren't complete. Each If must have an End If. I find the easiest way to find these is to keep cutting out valid clauses until you're left with the offending bit (on a copy or in Word or something). Also, is that ElseIf at the top really in the code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    LOUISBUHAGIAR54 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Malta
    Posts
    3
    Actually the code had been used successfully for a long time. I recently decided to add the Do loop while cycle so that I can re-run a hospital admission. You can probably interpret this from the code. I did not add new If, else, elseif, endif clauses.

    Yes the elseif clause is there and had been there before. As I have stated in my quote the code demonstated is only a part of all the module.

    Many thanks.


    LB

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Indenting can help reveal issues:
    Code:
    Do
        admixxin = InputBox("Add the date of admission to hospital!", "Admitted to Hospital", , 3000, 3000)
        
        If StrPtr(admixxin) = 0 Then
            MsgBox "You have pressed cancel and the command will stop here!!!"
            Exit Sub
        End If
        ' the above sequence is in place so that if no admission date is available the command will stop here.
        
        licenzjat = InputBox("Add the date of discharge from Hospital", "Discharged from Hospital", "", 9000, 3000)
        sameta = ahhartaxahar
        If IsDate(licenzjat) = False Then
            If admixxin >= tibda Then
                hstay = ahhartaxahar - admixxin 'patient still in hospital by end of month.
            ElseIf admixxin < tibda Then
                hstay = ahhartaxahar - tibda + 1 ' patient in hospital throughout the month
            End If
        Else
            If admixxin >= tibda And CDate(licenzjat) <= ahhartaxahar Then
                hstay = CDate(licenzjat) - admixxin - 1
            ElseIf admixxin < tibda And CDate(licenzjat) <= ahhartaxahar Then
                hstay = CDate(licenzjat) - tibda
            End If
            messagg = MsgBox("Was the resident admitted to hospital again?", vbYesNoCancel, "Hospital admission no " & numru)
            tothstay = tothstay + hstay
            numru = numru + 1
        End If
    Loop While Message = vbYes
    Loop line is in wrong place. It has interrupted an existing If Then Else block. Without the complete procedure, not sure where should be. The above correction will probably result in an unpaired End If below the Loop.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If all you did was add the loop, you've likely broken an If/Then block. You can't have

    If..

    Do...

    End If

    Loop
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    LOUISBUHAGIAR54 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Location
    Malta
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    If all you did was add the loop, you've likely broken an If/Then block. You can't have

    If..

    Do...

    End If

    Loop

    Dear Paul,


    You're a great man. You solved the issue. Working perfectly now. Many thanks.

    Louis

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! Welcome to the site by the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. HEEELP: Mulitple data for same record
    By Ignace in forum Access
    Replies: 3
    Last Post: 07-08-2011, 09:14 AM
  2. Replies: 6
    Last Post: 02-13-2011, 06:02 PM
  3. Calculating the Sum of Mulitple Columns
    By ARickert in forum Queries
    Replies: 22
    Last Post: 12-27-2010, 09:06 PM
  4. Query Can it be Done? Mulitple finds
    By Canadiangal in forum Queries
    Replies: 3
    Last Post: 02-28-2010, 03:45 PM
  5. Condense Mulitple Records
    By jquickuk in forum Queries
    Replies: 1
    Last Post: 08-10-2009, 08:43 AM

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