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

    Adding correct charachter For Numeric

    Hi Guy's, what is the correct character needed for the highlighted please ?

    I know
    String Variables are "' & _


    Date Variables are #" _
    Numeric don't normally have closing characters are declaring

    My debug window shows correct result but i have syntax wrong here ?

    Code:
    Dim sSQL As String, sDriver As StringDim iRoute As Integer
    Dim dtDate As Date
    
    
    iRoute = Me.RouteNo
    dtDate = Me.DelDate
    sDriver = Me.Driver
    
    
    Select Case iRoute
    
    
    Case Is = 0
    
    
    Exit Sub
    
    
    Case Else
    
    
    sSQL = "UPDATE tblRoutePlan SET tblRoutePlan.RouteNo = " & iRoute & " & " _
                & "WHERE (((tblRoutePlan.DelDate)= #" & dtDate & "#) " _
                & "AND ((tblRoutePlan.Driver) = '" & sDriver & "'));"
        
        Debug.Print sSQL
    
    
    DoCmd.SetWarnings False
        DoCmd.RunSQL sSQL
    DoCmd.SetWarnings True
    
    
    If Me.Dirty Then Me.Dirty = False
    
    
    Forms!frmRouteEdit!frmEditRouteWeekDS.Requery
    
    
    
    
    End Select

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,948
    And yet you do not show the output from the debug.print ?
    I always put a space at the start of any continuation lines, so I do not have to scroll to the right all the time to see if one is there?

    Try
    Code:
    sSQL = "UPDATE tblRoutePlan SET tblRoutePlan.RouteNo = " & iRoute  _
                & " WHERE (((tblRoutePlan.DelDate)= #" & dtDate & "#) " _
                & " AND ((tblRoutePlan.Driver) = '" & sDriver & "' & "));"
    Edited in Notepad.
    Plus your date needs to be in mm/dd/yyyy or yyyy-mm-dd format?
    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
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks WGM, the output had data in that i could have wiped out before posting but all criteria's looked correct so was easier to confirm data correct

    So what i have picked up on is a different and potentially better method having spaces at the start of continuous lines

    also numeric variables don't have closing parameters and see that you have removed in your edit

    Thanks, will adjust and update

  4. #4
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thanks WGM fixed

    Code:
    Dim sSQL As String, sDriver As StringDim iRoute As Integer
    Dim dtDate As Date
    
    
    iRoute = Me.RouteNo
    dtDate = Format(Me.DelDate, "mm/dd/yyyy")
    sDriver = Me.Driver
    
    
    Select Case iRoute
    
    
    Case Is = 0
    
    
    Exit Sub
    
    
    Case Else
    
    
    sSQL = "UPDATE tblRoutePlan SET tblRoutePlan.RouteNo = " & iRoute _
                & " WHERE (((tblRoutePlan.DelDate)= #" & dtDate & "#)" _
                & " AND ((tblRoutePlan.Driver) = '" & sDriver & "'));"
        
        Debug.Print sSQL
    
    
    DoCmd.SetWarnings False
        DoCmd.RunSQL sSQL
    DoCmd.SetWarnings True
    
    
    If Me.Dirty Then Me.Dirty = False
    
    
    Forms!frmEditRoute!frmEditRouteWeekDS.Requery
    
    
    
    
    End Select

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,948
    TBH I hardly ever use the continuation character, preferring to use strSQL = srtSQL & whatever
    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

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,948
    You do NOT run the sql until you get the syntax correct, so comment it out until you reckon your sql is correct. No big deal for selects, but essential for update/delete queries.
    I would always stat with a Select until I have the correct data, before changing to an update query.
    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

  7. #7
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi WGM, when testing for results in immediate window, i always use exit sub after debug.print to halt procedure, that is when i had correct info in immediate window then removed exit sub to continue

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

Similar Threads

  1. Replies: 4
    Last Post: 05-04-2022, 02:42 PM
  2. Replies: 7
    Last Post: 12-04-2021, 06:07 PM
  3. Replies: 1
    Last Post: 05-27-2020, 01:56 AM
  4. Replies: 2
    Last Post: 05-07-2015, 04:12 PM
  5. Replies: 5
    Last Post: 09-12-2014, 06:41 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