Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,010

    Any data in the recordset as you are not formatting the date?
    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

  2. #17
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    I can't say it enough, you are all a great on here, although it should be just about automatic for me, i still get lost wit hit sometimes, i could do with a step by number of sequence and keep hold of it

    ie:
    1 Set XL
    2 Set WB
    3 set WS
    4 Set RS
    5 Do Until
    6 XL Row Count

    etc etc...,

    all working good

    I sometimes wonder, difficult things in life are easy and easy things are difficult

    Working Code

    Code:
     iCondition = InputBox("Enter The Condition Of Your Images ?" & vbCrLf & vbCrLf & _        
            Chr(149) & " 1 " & Chr(149) & "Good, No Visible Damage" & vbCrLf & vbCrLf & _
            Chr(149) & " 2 " & Chr(149) & "Good, Packaging Damage" & vbCrLf & vbCrLf & _
            Chr(149) & " 3 " & Chr(149) & "Marked, Very Light Damage" & vbCrLf & vbCrLf & _
            Chr(149) & " 4 " & Chr(149) & "Marked, Heavy Damage", "ENTER CONDITION", "1")
            Select Case iCondition
                Case Is = 1
                    sDamage = "Good, No Visible Damage"
                Case Is = 2
                    sDamage = "Good, Packaging Damage"
                Case Is = 3
                    sDamage = "Marked, Very Light Damage"
                Case Is = 4
                    sDamage = "Marked, Heavy Damage"
            End Select
            
        strPC = "Customer PostCode Removed"
     
        pOpen = "T:\DMT Ltd\Images\Stored Images\Images\Customer Name Folder Removed\"
        fOpen = "Condition Report.xlsx"
        
        Set apXL = CreateObject("Excel.Application")
        Set xlWB = apXL.Workbooks.Open(pOpen & fOpen)
        Set xlWS = xlWB.Worksheets("Sheet1")
        apXL.Visible = False
        
        dtShipDate = Forms!frmMainMenu!frmIndex1!cboShipmentDateIndex1
        
        Set rs = CurrentDb.OpenRecordset("Select * From tblEdit WHERE ShipmentDate = #" & Format(dtShipDate, "mm/dd/yyyy") & "# And PostCode = '" & strPC & "'")
        
        With xlWS
            
            intLR = .Cells(.Rows.Count, 1).End(xlUp).Row
            
            Do Until rs.EOF
                
                strSL = rs.Fields("SONumber")
                strMFG = rs.Fields("ItemNo")
                dtShipDate = rs.Fields("ShipmentDate")
                sDelTo = rs.Fields("DelTo")
                strPostCode = rs.Fields("PostCode")
             
            xlWS.Cells(intLR + 1, 1) = Format(dtShipDate, "dd-mm-yyyy")
            xlWS.Cells(intLR + 1, 2) = sDelTo
            xlWS.Cells(intLR + 1, 3) = strPostCode
            xlWS.Cells(intLR + 1, 4) = strSL
            xlWS.Cells(intLR + 1, 5) = strMFG
            xlWS.Cells(intLR + 1, 6) = sDamage
            xlWS.Cells.EntireColumn.HorizontalAlignment = xlLeft
                 
            rs.MoveNext
            
            intLR = intLR + 1
            
            Loop
            
            xlWB.Save
            xlWB.Close
            apXL.Quit
            
        End With
           
        Debug.Print strSQL
        
    Set apXL = Nothing
    
    
    
    
    Application.FollowHyperlink pOpen & fOpen

    The only part on the excel result is the date is USA mm/dd/yyyy, sometimes setting the initial variable with dates in, i find it works better to format mm/dd/yyyy in the declared variable then on any excel files / reports / forms / query results change back to dd/mm/yyyy for UK dates

    However you are all legends (this is not leg-ends) end of your legs

    Result:

    Click image for larger version. 

Name:	Capture.JPG 
Views:	8 
Size:	73.6 KB 
ID:	50656

    Finally I think my next task with this is what if 1 item is damaged and 1 is not so then i would write an adjust option and have similar code to load into recordset just the Sales Order (SONumber) within the same shipment date

    Thanks again guys

  3. #18
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Finally I think my next task with this is what if 1 item is damaged and 1 is not so then i would write an adjust option and have similar code to load into recordset just the Sales Order (SONumber) within the same shipment date

    Thanks again guys


    Or i set another input box asking if all items are not damaged then select case and add which one or edit in another event procedure

  4. #19
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,010
    Dave,
    Real dates are just numbers.
    You need the format your date for the sql string so Access can find the correct date, but the date should still be in your regional settings, which is UK.
    So DO NOT format the date for the cell, just in the sql string.

    Plus if you use Format() for that cell, you have now changed a date into a string.
    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

  5. #20
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks WGM, so just to confirm, are you referring to:

    Code:
      dtShipDate = Forms!frmMainMenu!frmIndex1!cboShipmentDateIndex1    
        Set rs = CurrentDb.OpenRecordset("Select * From tblEdit WHERE ShipmentDate = #" & Format(dtShipDate, "mm/dd/yyyy") & "# And PostCode = '" & strPC & "'")
        
        With xlWS
            
            intLR = .Cells(.Rows.Count, 1).End(xlUp).Row
            
            Do Until rs.EOF
                
                strSL = rs.Fields("SONumber")
                strMFG = rs.Fields("ItemNo")
                dtShipDate = Format(rs.Fields("ShipmentDate"), "dd-mmm-yyyy")
                sDelTo = rs.Fields("DelTo")
                strPostCode = rs.Fields("PostCode")
             
            xlWS.Cells(intLR + 1, 1) = dtShipDate
            xlWS.Cells(intLR + 1, 2) = sDelTo
            xlWS.Cells(intLR + 1, 3) = strPostCode
            xlWS.Cells(intLR + 1, 4) = strSL
            xlWS.Cells(intLR + 1, 5) = strMFG
            xlWS.Cells(intLR + 1, 6) = sDamage
            xlWS.Cells.EntireColumn.HorizontalAlignment = xlLeft
    And Not:

    Code:
      dtShipDate = Forms!frmMainMenu!frmIndex1!cboShipmentDateIndex1    
        Set rs = CurrentDb.OpenRecordset("Select * From tblEdit WHERE ShipmentDate = #" & Format(dtShipDate, "mm/dd/yyyy") & "# And PostCode = '" & strPC & "'")
        
        With xlWS
            
            intLR = .Cells(.Rows.Count, 1).End(xlUp).Row
            
            Do Until rs.EOF
                
                strSL = rs.Fields("SONumber")
                strMFG = rs.Fields("ItemNo")
                dtShipDate = Format(rs.Fields("ShipmentDate"), "dd-mmm-yyyy")
                sDelTo = rs.Fields("DelTo")
                strPostCode = rs.Fields("PostCode")
             
            xlWS.Cells(intLR + 1, 1) = dtShipDate
            xlWS.Cells(intLR + 1, 2) = sDelTo
            xlWS.Cells(intLR + 1, 3) = strPostCode
            xlWS.Cells(intLR + 1, 4) = strSL
            xlWS.Cells(intLR + 1, 5) = strMFG
            xlWS.Cells(intLR + 1, 6) = sDamage
            xlWS.Cells.EntireColumn.HorizontalAlignment = xlLeft
    ?

  6. #21
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Or how would you set the date if not by Format() ?

    IN this instance, i am better setting the Excel column date setting ?

  7. #22
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,010
    Ok, let's take a step back.
    In your first block of code, you format the date from the recordset. So it becomes a string?
    Now, wherever you use that variable you will be inserting a string value, that looks like a date.

    Now if you DO NOT format that date from the recordset, and leave it as it is, (a s you did at the start. Did you not look at your sheet then?), it will remain a date.
    Now if you assign that to a cell, it will remain a date, and so will respect your regional settings.

    However, your question highlights the fact that you are not understanding the code you are writing?

    No need to set the date, unless you do not want it as per your system. We in the UK need to follow Access's requirement to supply dates in either mm/dd/yyyy or yyyy-mm-dd format.
    Once you can understand why, it is not that hard to work with dates in Access.
    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

  8. #23
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks WGM

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2021, 02:38 AM
  2. Replies: 5
    Last Post: 04-25-2017, 01:38 AM
  3. How would I import the excel sheet like this to Access
    By Arvine in forum Import/Export Data
    Replies: 3
    Last Post: 05-18-2014, 03:47 PM
  4. Transferring Excel Sheet To Access
    By athyeh in forum Access
    Replies: 22
    Last Post: 07-26-2013, 02:18 PM
  5. Replies: 26
    Last Post: 01-08-2013, 04:55 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