Results 1 to 6 of 6
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329

    Run Time error

    Hi Guy's this one i can't see the trees nor the wood for the trees !!!



    I am trying to return a count of how many records are within the date (myDate) then move them to next week (myDate + 7)

    The code I have here comes up with run time error see below, how can I group the DelTo and The Status of Records That Are Planning Or On Hold ?

    Ideally in the strRS string, show the records in the MsgBox Before Continuing to Move to Next Week but only show 1 record per DelTo ?

    So i can have 6 records for 1 x Joe Bloggs that says Planning, i Can have 3 x Records for Fred Bloggs that says On Hold, but grouping the rrecordset and displaying 1 line On MsgBox such as:

    Fred Bloggs On Hold
    Joe Bloggs Planning

    Also unsure If we can add the quantity of each one also

    Fred Bloggs On Hold x 3
    Joe Bloggs Planning x 6

    Do you want to continue to move the x 9 records to next week

    Code:
    myDate = Me.cboShipmentDateIndex1    NewDate = DateAdd("d", 7, myDate)
        strPlan = "Planning"
        strHold = "On Hold"
        Set rs = CurrentDb.OpenRecordset("Select tblEdit.DelTo, tblEdit.ShipmentDate, tblEdit.Status From tblEdit WHERE Status = '" & strPlan & "' Or Status = '" & strHold & "' And ShipmentDate = #" & myDate & "# GROUP BY DelTo")
        i = rs.RecordCount
        strRS = strRS & rs.Fields("DelTo") & " - " & rs.Fields("Status") & vbCrLf
        If MsgBox("Do You Want To Move: " & i & " " & "Records" & vbNewLine & _
        strRS & vbNewLine & _
        vbTab & "From: " & myDate & vbNewLine & _
        vbTab & "to: " & NewDate & " " & "?", vbQuestion + vbYesNo, "MOVE RECORDS") = vbNo Then
        DoCmd.CancelEvent
        Else
        Do Until rs.EOF
        rs.Edit
        rs.Fields("ShipmentDate") = NewDate
        rs.MoveNext
        Loop
        End If
    ShipmentDate Is a Field set as Date

    Click image for larger version. 

Name:	Run Time Error.JPG 
Views:	11 
Size:	16.6 KB 
ID:	47328

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Make a query,not sql,
    it will tell you the problem, then you can correct it.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,284
    You need to include the field mentioned in some way, even if not null.
    I' surround your ors with brackets to be on the safe side.
    Recordcount might not be correct unless you move last before looking at it?
    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

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    remove the GROUP BY DelTo part of the code
    or if you need it, either include the other fields or remove them

  5. #5
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Okie Dokie guys thank you will test as suggested

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    So I am going to test the SQL based on this query

    Click image for larger version. 

Name:	Query.JPG 
Views:	9 
Size:	42.9 KB 
ID:	47329

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

Similar Threads

  1. Replies: 3
    Last Post: 04-06-2021, 06:25 AM
  2. Replies: 6
    Last Post: 02-03-2020, 07:09 PM
  3. Replies: 13
    Last Post: 05-31-2019, 10:48 PM
  4. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  5. Replies: 0
    Last Post: 07-16-2012, 05:42 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