Results 1 to 6 of 6
  1. #1
    lawdy is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jan 2013
    Posts
    216

    What to do with a no current record query

    The sub works good as long as there are records to locate. But when there isn't, I get a No Current Record error. The internet says the cure is to use dsum with the name of the query. I not sure what the name of the query is. Please help. The code is:


    Sub modCal_addJobsToCal() ' put job names on frmCal_2025


    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Dim strJob As String
    Dim lngWeek As Long
    Dim lngDay As Long
    Dim strDay As String
    Dim lngLine As Long
    Dim strPosition As String
    Dim dateDate As Date

    For lngWeek = 1 To 1 ' 5
    For lngDay = 1 To 7 ' 14
    strDay = CStr(lngDay)
    Select Case strDay
    Case 1, 2, 3, 4, 5, 6, 7, 8, 9: strDay = "0" & strDay
    Case Else: strDay = strDay


    End Select
    For lngLine = 101 To 103 ' 120
    dateDate = DateValue(Forms![frmCal_2025].Controls("tbD1" & strDay))
    strPosition = "tbJ" & CStr(lngWeek) & CStr(lngDay) & CStr(lngLine)

    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT tblCal_2025.fDate, tblCal_2025.fStrLineNo, tblCal_2025.fLngProposalNo, " _
    & "tblCal_2025.fTxtService, tblProposal.fTxtPropertyName " _
    & "From tblCal_2025 INNER JOIN tblProposal " _
    & "ON tblCal_2025.fLngProposalNo = tblProposal.fLngProposalNo " _
    & "WHERE (((tblCal_2025.fDate) = #" & dateDate & " # " _
    & "AND (tblCal_2025.fStrLineNo) = '" & CStr(lngLine) & "'))" _
    & "Order BY tblCal_2025.fDate, tblCal_2025.fStrLineNo", _
    dbOpenSnapshot, dbReadOnly)

    With rs
    Debug.Print "date " & rs!fDate & " ProposalNo " & rs!fLngProposalNo & " LineNo " & rs!fStrLineNo
    If Not (.BOF And .EOF) Then
    .MoveFirst
    End If
    strJob = ![fDate] & " " & ![fLngProposalNo] & " " & !fTxtPropertyName ' this makes the value of the line
    End With
    With Forms![frmCal_2025].Controls(strPosition)
    .Value = strJob
    .BackColor = 14810879
    End With
    Next lngLine
    Next lngDay
    Next lngWeek
    Set rs = Nothing
    Set db = Nothing
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Check the .RecordCount property?
    For any domain function the criteria would be
    Code:
    "WHERE (((tblCal_2025.fDate) = #" & dateDate & "#" & " AND (tblCal_2025.fStrLineNo) = '" & CStr(lngLine) & "'))"
    
    I do not believe you should have spaces before the second # ?, and I hope you use mm/dd/yyyy format in your system? That would not work here in the UK.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Code:
    frmCal_2025
    tblCal_2025
    
    Real bad idea if your intention is to add a new table and form every year.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    299
    Please post code like this
    Code:
    Dim db As DAO.DatabaseDim rs As DAO.Recordset
    
    
    Dim strJob As String
    Dim lngWeek As Long
    Dim lngDay As Long
    Dim strDay As String
    Dim lngLine As Long
    Dim strPosition As String
    Dim dateDate As Date
    
    
    For lngWeek = 1 To 1 ' 5
        For lngDay = 1 To 7 ' 14
            strDay = CStr(lngDay)
            Select Case strDay
                Case 1, 2, 3, 4, 5, 6, 7, 8, 9: 
                    strDay = "0" & strDay
                Case Else: 
                    strDay = strDay
            End Select
            
            For lngLine = 101 To 103 ' 120
                dateDate = DateValue(Forms![frmCal_2025].Controls("tbD1" & strDay))
                strPosition = "tbJ" & CStr(lngWeek) & CStr(lngDay) & CStr(lngLine)
    
    
                Set db = CurrentDb
                Set rs = db.OpenRecordset("SELECT tblCal_2025.fDate, tblCal_2025.fStrLineNo, tblCal_2025.fLngProposalNo, " _
                            & "tblCal_2025.fTxtService, tblProposal.fTxtPropertyName " _
                            & "From tblCal_2025 INNER JOIN tblProposal " _
                            & "ON tblCal_2025.fLngProposalNo = tblProposal.fLngProposalNo " _
                            & "WHERE (((tblCal_2025.fDate) = #" & dateDate & " # " _
                            & "AND (tblCal_2025.fStrLineNo) = '" & CStr(lngLine) & "'))" _
                            & "Order BY tblCal_2025.fDate, tblCal_2025.fStrLineNo", _
                            dbOpenSnapshot, dbReadOnly)
    
    
                With rs
                    Debug.Print "date " & rs!fDate & " ProposalNo " & rs!fLngProposalNo & " LineNo " & rs!fStrLineNo
                    If Not (.BOF And .EOF) Then
                        .MoveFirst
                    End If
    
    
                    strJob = ![fDate] & " " & ![fLngProposalNo] & " " & !fTxtPropertyName ' this makes the value of the line
                End With
    
    
                With Forms![frmCal_2025].Controls(strPosition)
                    .Value = strJob
                    .BackColor = 14810879
                End With
            Next lngLine
        Next lngDay
    Next lngWeek
    
    
    Set rs = Nothing
    Set db = Nothing
    I have no idea what you are trying to do. You start with a for/next loop: For lngWeek = 1 To 1. Why a loop if you only perform it once?

    After that you have
    For lngDay = 1 To 7 with a case select
    Code:
    strDay = CStr(lngDay)        
    Select Case strDay
      Case 1, 2, 3, 4, 5, 6, 7, 8, 9: 
         strDay = "0" & strDay
      Case Else: 
         strDay = strDay
    End Select
    Why the SELECT CASE if lngDay/strDay never is bigger than 7?
    Groeten,

    Peter

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 11 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    lawdy,

    As others have suggested, it might be helpful if you could describe in plain English what you are trying to do. Once everyone understands the issue, you are likely to get more, focused responses.

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    you can test this:

    Code:
    Sub modCal_addJobsToCal() ' put job names on frmCal_2025
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strJob As String
    Dim lngWeek As Long
    Dim lngDay As Long
    Dim strDay As String
    Dim lngLine As Long
    Dim strPosition As String
    Dim dateDate As Date
    
    
    Set db = CurrentDb
    
    
    For lngWeek = 1 To 1 ' 5
            For lngDay = 1 To 7 ' 14
                    strDay = CStr(lngDay)
                    Select Case strDay
                    Case 1, 2, 3, 4, 5, 6, 7, 8, 9: strDay = "0" & strDay
                    Case Else: strDay = strDay
                    End Select
                    
                    For lngLine = 101 To 103 ' 120
                            dateDate = DateValue(Forms![frmCal_2025].Controls("tbD1" & strDay))
                            strPosition = "tbJ" & CStr(lngWeek) & CStr(lngDay) & CStr(lngLine)
                            
                            Set rs = db.OpenRecordset("SELECT tblCal_2025.fDate, tblCal_2025.fStrLineNo, tblCal_2025.fLngProposalNo, " _
                            & "tblCal_2025.fTxtService, tblProposal.fTxtPropertyName " _
                            & "From tblCal_2025 INNER JOIN tblProposal " _
                            & "ON tblCal_2025.fLngProposalNo = tblProposal.fLngProposalNo " _
                            & "WHERE (((tblCal_2025.fDate) = #" & dateDate & " # " _
                            & "AND (tblCal_2025.fStrLineNo) = '" & CStr(lngLine) & "'))" _
                            & "Order BY tblCal_2025.fDate, tblCal_2025.fStrLineNo", _
                            dbOpenSnapshot, dbReadOnly)
                            
                            strJob = ""
                            
                            With rs
                                    Debug.Print "date " & rs!fDate & " ProposalNo " & rs!fLngProposalNo & " LineNo " & rs!fStrLineNo
                                    If Not (.BOF And .EOF) Then
                                            .MoveFirst
                                            strJob = ![fDate] & " " & ![fLngProposalNo] & " " & !fTxtPropertyName ' this makes the value of the line
                                    End If
                                    .Close
                            End With
                            With Forms![frmCal_2025].Controls(strPosition)
                                    .Value = strJob
                                    .BackColor = 14810879
                            End With
                            
                    Next lngLine
            Next lngDay
    Next lngWeek
    Set rs = Nothing
    Set db = Nothing
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2022, 06:49 PM
  2. Replies: 5
    Last Post: 06-10-2021, 09:04 AM
  3. Replies: 5
    Last Post: 08-18-2018, 10:23 AM
  4. Replies: 0
    Last Post: 05-04-2010, 06:39 AM
  5. copy current record to new record
    By er_manojbisht in forum Forms
    Replies: 1
    Last Post: 02-27-2010, 05:31 PM

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