Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    344
    @CJ I couldn't get that line to compile. I best guessed and put &" ahead of WHERE but then got an error on Track External name not defined.
    Track is definitely a number data type.


    This is too much of a problem so I've added a new field and not changing Track now. But it'd still be interesting to see the correct sql construction.

  2. #17
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    I suggest you post a zipped db with just enough to replicate the issue.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    sorry should be
    sql = "UPDATE Tracks SET Track = " & 1+([Track]/10) & " WHERE tID=" & c - 1

  4. #19
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    344
    I still can't get it to work so will do as @Micron suggests and upload it. Neither of the sql strings work, (External name not defined.) but at one time something did work (but not correctly).
    That's now deleted.
    I'm intrigued what the "/10" should do and what would put the "." in. And why the error.
    Attached Files Attached Files

  5. #20
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    You aren't concatenating [Track] from a form, you want to just use the field from the table:

    sql = "UPDATE Tracks SET Track =1 & '.' & [Track] WHERE tID=" & c - 1

    Note that 1.10 shows as 1.1 in number field therefore is not distinguished from the 1.1 items (same for 1.20 and 1.2). Options are to

    1) save to a text field
    or
    2) save the 1 through 9 values as 1.01, etc. and set for 2 decimal place display
    sql = "UPDATE Tracks SET Track = 1 + ([Track] / 100) WHERE tID=" & c - 1


    Why c - 1 and not just 1001 ?
    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. #21
    Join Date
    Apr 2017
    Posts
    1,679
    The field Track is a number (a double one).
    In your module, you are trying to run an update query
    Code:
    sql = "UPDATE Tracks SET Track = " & 1 + ([Track] / 10) & " WHERE tID=" & c - 1
    This query returns an error when run, because it is trying to add to string "UPDATE Tracks SET Track = " the value of expression (1 + ([Track] / 10)) - but there is no variable [Track] defined for this sub, not can the procedure to read it from somewhere. To be working, this code string must be
    Code:
    sql = "UPDATE Tracks SET Track = " & "1 + ([Track] / 10)" & " WHERE tID=" & c - 1
    Now about what you get when you run this sub:
    When Track = 1, you get 1 + 1/10 = 1.1;
    When Track = 10, you get 1 + 10/10 = 2;
    When Track = 11, you get 1 + 11/10 = 2.1;
    When Track = 20, you get 1 + 20/10 = 3

    Is this what you really want? Or do you really want values 1.01, 1.1, 1.11, 1.2, etc. instead. This you can get e.g. with query like
    Code:
    SELECT tID, CDbl("1." & RIGHT("00" & CStr(Track), 2)) AS ConvertedTrack
    It assumes the original value of Track never gets >= 100. Otherwise you have to increase the number trailing zeros in ConvertedTrack formula of query.
    And be aware, it depends on you regional settings, i.e. on your decimal delimiter, are you using "1." or "1," in same formula.

  7. #22
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    344
    Thanks @June7 , this has been quite interesting, I was looking at a Form but had not requeryed it. So may not have seen some previous changes/attempts.
    I see what you mean about not distinguished, I'm now not using this format.
    Would you know what caused the
    (External name not defined. error? It doesn't happen now.
    Originally c was going to be passed to the procedure, I had just left it for testing one record.

  8. #23
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    The posted db did not have a form. Code was in a general module and the concatenated reference to [Track] was meaningless. There was no [Track] object (such as field or textbox on form) to reference.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2022, 11:28 AM
  2. Replies: 6
    Last Post: 07-09-2021, 10:38 AM
  3. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 2
    Last Post: 08-30-2012, 07:59 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