Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Join Date
    Jan 2014
    Posts
    28

    Angry compile error do without loop

    Hey Guys i was just wandering if you could help me solve the error I come up with
    compile error do without loop


    Code:
    Private Sub cboTime_Enter()
    Dim i As Date, n As Integer, oRS As DAO.Recordset
    Dim sSQL As String, dDuration As Date
    Dim dLowerbreak As Date, dUpperBreak As Date
    
    cboTime.RowSourceType = "Value List"
    cboTime.RowSource = ""
    
    If IsNull(Start) Then Exit Sub Else i = Start
    
    If Me.NewRecord = True Then
       DoCmd.RunCommand acCmdSaveRecord
    End If
    
    sSQL = "SELECT DoctorsID,AppointDate,AppointTime"
    sSQL = sSQL & " FROM qrySubformAppoints"
    sSQL = sSQL & " WHERE DoctorsID=" & Me.ID & _
    " AND AppointDate=#" & Me.txtAppointDate & "#"
    Set oRS = CurrentDb.OpenRecordset(sSQL)
    dDuration = TimeValue("00:30")
    dLowerbreak = Break - TimeValue("00:25") 'Break is a field
    dUpperBreak = Break + TimeValue("00:25")
    
    If oRS.RecordCount = 0 Then
       Do
          If i <= dLowerbreak Or i >= dUpperBreak Then
             cboTime.AddItem i
          End If
          i = i + dDuration
       Loop Until i >= txtEnd
    Else
       Do
          If i <= dLowerbreak Or i >= dUpperBreak Then
             oRS.FindFirst "[AppointTime] Between #" & i - TimeValue("00:00:05") & _
             "# And #" & i + TimeValue("00:00:05") & "#"
             If oRS.NoMatch Then cboTime.AddItem i
          End If
    oRS.Close
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    If you post code between CODE tags, indentation will be retained, assuming you use indentation in your code. It makes code much easier to read.

    I edited your post to show the indentation. Can you see what is missing? Second Do does not have matching Loop and the outermost If Then does not have an End If.
    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.

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Its telling you pretty much exactly what the issue is.
    You have two "Do" loops, but your second (last) one does not have a "Loop" command.

    This line also looks a little odd to me:
    Code:
    	If IsNull(Start) Then Exit Sub Else i = Start
    What is Start? Is it a variables? I do not see it defined or set anywhere.
    If it is a literal text value, it needs to be enclosed in quotes, i.e.
    Code:
    	If IsNull(Start) Then Exit Sub Else i = "Start"

  4. #4
    Join Date
    Jan 2014
    Posts
    28
    Sorry i am new to VBA coding
    i copied the code from a video on youtube
    Start is a field name
    www.youtube.com/watch?v=hQuXVxGFm7s

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    So Start is a field on form?

    Try:

    If IsNull(Me.Start) Then Exit Sub Else i = Me.Start

    Did you review my previous post?
    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.

  6. #6
    Join Date
    Jan 2014
    Posts
    28
    That does not make a difference.
    Like i said i am new to VBA so i did not understand what you said in your previous post.
    The coding is from the guy who uploaded it on youtube

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Then you need to learn programming basics. Look at the first Do in the code. It has a matching Loop line. The second Do does not have a Loop line.

    Look at each If Then structure. The first one is an all-on-one-line approach. All the others are split to separate lines. These must have an End If line. They must be in pairs.

    I can't view the YouTube now so can't say if the errors started there but they are difinitely present in your code.
    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.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This will get rid of the errors but it probably will not give the desired results. Like June said, you need to learn how to debug. Study this and see if it makes sense. Study the results if you can get it to run.

    Code:
    Dim i As Date, n As Integer, oRS As DAO.Recordset
    Dim sSQL As String, dDuration As Date
    Dim dLowerbreak As Date, dUpperBreak As Date
    cboTime.RowSourceType = "Value List"
    cboTime.RowSource = ""
    'If IsNull(Start) Then Exit Sub Else i = Start
    If IsNull(Me.Start) Then Exit Sub Else i = Me.Start
     
            If Me.NewRecord = True Then
               DoCmd.RunCommand acCmdSaveRecord
            End If
        
        sSQL = "SELECT DoctorsID,AppointDate,AppointTime"
        sSQL = sSQL & " FROM qrySubformAppoints"
        sSQL = sSQL & " WHERE DoctorsID=" & Me.id & _
        " AND AppointDate=#" & Me.txtAppointDate & "#"
        Set oRS = CurrentDb.OpenRecordset(sSQL)
        dDuration = TimeValue("00:30")
        dLowerbreak = Break - TimeValue("00:25") 'Break is a field
        dUpperBreak = Break + TimeValue("00:25")
        
        If oRS.RecordCount = 0 Then
           Do
              If i <= dLowerbreak Or i >= dUpperBreak Then
                 cboTime.AddItem i
              End If
              i = i + dDuration
           Loop Until i >= txtEnd
        Else
        '   Do
              If i <= dLowerbreak Or i >= dUpperBreak Then
                 oRS.FindFirst "[AppointTime] Between #" & i - TimeValue("00:00:05") & _
                 "# And #" & i + TimeValue("00:00:05") & "#"
                 If oRS.NoMatch Then cboTime.AddItem i
              End If
        oRS.Close
        End If

  9. #9
    Join Date
    Jan 2014
    Posts
    28
    I am now getting a error with the following code
    Private Sub cboTime_AfterUpdate()
    subform.SetFocus
    DoCmd.GoToControl "AppointTime"
    DoCmd.GoToRecord , , acNewRec
    subform.Form.Controls("AppointTime") = Me.cboTime
    subform.Form.Controls("AppointDate") = Me.txtAppointDate
    subform.Form.Controls("cboClient").SetFocus
    subform.Form.Controls("cboClient").Dropdown
    End Sub

    the subform.setfocus gets highlighted in yellow

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Except probably should put the oRS.Close below the End If.

    What is the exact error message? Is your subform actually named 'subform'?
    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.

  11. #11
    Join Date
    Jan 2014
    Posts
    28
    but then would it not be better of to delete the last end if
    rather then having it as
    End If
    End If
    oRS.close

    How do you know what the subform is called.
    under property sheet it is tblAppointments subform

  12. #12
    Join Date
    Jan 2014
    Posts
    28
    There is no error message

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    If and End If must be in PAIRS if using multi-line structure. Doesn't matter if one follows another - that is nested If Then. But what last End If are you talking about? ItsMe's correction provides the missing End If.

    Use the actual form name.

    You need to understand that a subform is created by placing a subform/subreport container control on another form/report. The container control holds an object (table, query, form, or report). Should give the container control a name different from the object it holds, like ctrAppointment. So your code would be like:

    Me.ctrAppointment.SetFocus
    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.

  14. #14
    Join Date
    Jan 2014
    Posts
    28
    sorry how do you find out the name
    dont forget i am completely new to this.
    i am doing a course

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Click on the subform container and look in the Other tab of the property sheet. I usualy left click in an open area and swoop of to ensure the selection of the container and not an object inside the container.

    And june is correct. The oRS.Close should go after the last End if. Better yet
    End If
    End If
    oRS.close
    Set oRS = Nothing

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  4. Replies: 7
    Last Post: 06-08-2012, 09:55 PM
  5. Replies: 6
    Last Post: 09-28-2011, 09:20 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