Results 1 to 4 of 4
  1. #1
    Hans Karlsson is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    1

    Convert decimal comma to decimal point

    I have a database with these fields:
    Name String
    DateTime1 Date/time
    DateTime2 Date/time

    I want to select records where the difference between DateTime2 and DateTim1 is above a specified number of minutes.

    The code below works if I want to select records where the difference between the two DateTimefields is longer than 4 minutes. (0.00277777777777778 = 4 minutes)

    Sub QueryTest1()
    Dim strQuery As String
    Dim dbs As Database
    Set dbs = CurrentDb

    On Error Resume Next
    DoCmd.DeleteObject acQuery, "qryDisplayResult" 'Delete query if exist

    strQuery = "SELECT tblTest.Name, Count(tblTest.Name) AS AntalförName " _
    & "FROM tblTest " _
    & "WHERE ((([date2] - [date1]) > 6.94444444444444E-04)) " _
    & "GROUP BY tblTest.Name;"

    Call CurrentDb.CreateQueryDef("qryDisplayResult", strQuery) 'Create the query
    DoCmd.OpenQuery "qryDisplayResult" 'Display the query

    End Sub



    I want to create a more flexible code where I can specify the time (whole minutes) in an Inputbox. My problem is that I use a Swedish version of Access 2010 and we use a comma as decimal limiter and not a point. When I calculate minutes from the inputbox with 0.000694444444444444 (= 1 minute) the result shows with a decimal comma ant not with a point witch VBA requires.

    Sub QueryTest2()
    Dim strQuery As String
    Dim intMinutes As Integer
    Dim dblMinutesAsDecimal As Double
    Dim dbs As Database
    Set dbs = CurrentDb

    On Error Resume Next
    DoCmd.DeleteObject acQuery, "qryDisplayResult" 'Delete query if exist

    intMinutes = InputBox("Select minutes")
    dblMinutesAsDecimal = intMinutes * 6.94444444444444E-03

    strQuery = "SELECT tblTest.Name, Count(tblTest.Name) AS AntalförName " _
    & "FROM tblTest " _
    & "WHERE ((([date2] - [date1]) > " & dblMinutesAsDecimal & ")) " _
    & "GROUP BY tblTest.Name;"

    Call CurrentDb.CreateQueryDef("qryDisplayResult", strQuery) 'Create the query
    DoCmd.OpenQuery "qryDisplayResult" 'Display the query

    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What result - the query output? Why is decimal comma display an issue?
    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.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Instead of using [date2] - [date1], why not use the DateDiff() function:

    DateDiff("n"), [date1], [date2]) > NumberOfMinutes

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Good catch linq. Subtraction of dates defaults to day unit. As linq suggests, instead of converting the minutes input to decimal day, use DateDiff and specify minutes with "n" parameter.
    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.

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

Similar Threads

  1. Add decimal in position
    By BrianF in forum Import/Export Data
    Replies: 4
    Last Post: 04-15-2013, 12:18 PM
  2. Decimal Places
    By momodoujimnjie in forum Access
    Replies: 1
    Last Post: 01-09-2013, 04:49 AM
  3. Replies: 0
    Last Post: 10-22-2012, 02:45 PM
  4. Need Currency or Decimal Help!
    By Jaricketts in forum Access
    Replies: 2
    Last Post: 08-19-2010, 09:39 PM
  5. Converting HH:MM to decimal
    By katrinanyc926 in forum Queries
    Replies: 5
    Last Post: 08-13-2010, 02:39 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