Results 1 to 8 of 8
  1. #1
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108

    Excel Formula into Access Query

    Morning!

    I currently use a formula in Excel to convert a time into a readable format. I've recently moved over to using Access, as it's much better placed for the work i'm trying to achieve. The problem is; I don't know how to replicate the formula into an Access query.

    Could anybody help? The excel formula is

    Code:
    =FLOOR(A1,1) & ":" & ROUND(60*(A1-FLOOR(A1,1)),0)
    I've tried changing 'A1' to the column name ("Start Time"), but that doesn't work.

    Regards,
    Dr4ke

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Do not know whether I have understood things correctly :

    Just check out if below gives some guidelines :

    Code:
    SELECT 
        myTable.[StartTime], 
        Int([StartTime]) AS Expr2, 
        [StartTime]-[Expr2] AS Expr3, 
        60*[Expr3] AS Expr4, 
        Round([Expr4],0) AS Expr5, 
        [Expr2] & ":" & [Expr5] AS Expr6
    FROM 
        myTable;
    Thanks

  3. #3
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Perfect! Thank you!!

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Glad you found it helpful.

    Thanks

  5. #5
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    One more quick question, I need to do this for more than 1 column; can I do multiple SELECT's? I've tried to no avail... The ones I would require are...

    Code:
    SELECT 
        myTable.[Resp Time], 
        Int([Resp Time]) AS Expr2, 
        [Resp Time]-[Expr2] AS Expr3, 
        60*[Expr3] AS Expr4, 
        Round([Expr4],0) AS Expr5, 
        [Expr2] & ":" & [Expr5] AS Expr6
    FROM 
        myTable;
    Code:
    SELECT 
        myTable.[Start Time], 
        Int([Start Time]) AS Expr2, 
        [Start Time]-[Expr2] AS Expr3, 
        60*[Expr3] AS Expr4, 
        Round([Expr4],0) AS Expr5, 
        [Expr2] & ":" & [Expr5] AS Expr6
    FROM 
        myTable;
    Code:
    SELECT 
        myTable.[Fix Time], 
        Int([Fix Time]) AS Expr2, 
        [Fix Time]-[Expr2] AS Expr3, 
        60*[Expr3] AS Expr4, 
        Round([Expr4],0) AS Expr5, 
        [Expr2] & ":" & [Expr5] AS Expr6
    FROM 
        myTable;

    Can you help me

  6. #6
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    1) Avoid using spaces in Column Names.

    2) Your question is a perfect candidate for a User made Function. Make a function, which uses the logic & then call the function whenever you want to use it on any field, something like below.

    Try saving a function like below :


    Code:
    Function TheOutputTime(TheInputTime As Double)
        TheOutputTime = Int(TheInputTime) & ":" & Round(60 * (TheInputTime - Int(TheInputTime)), 0)
    End Function
    & then
    use the function in your query

    Code:
    SELECT 
    	myTable.StartTime, 
    	myTable.EndTime, 
    	TheOutputTime([StartTime]) AS TheStartTime, 
    	TheOutputTime([EndTime]) AS TheEndTime
    FROM 
    	myTable;
    Note : My VBA skills are not worth speaking about.

    Thanks

  7. #7
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Have tried this, but it's throwing up errors; below is what I tried

    Code:
    Function TheOutputTime(TheInputTime As Double)
        TheOutputTime = Int(TheInputTime) & ":" & Round(60 * (TheInputTime - Int(TheInputTime)), 0)
    End Function
    SELECT 
     DaisyMSR.StartTime, 
    DaisyMSR.RespTime,
     DaisyMSR.EndTime, 
     TheOutputTime([StartTime]) AS TheStartTime, 
    TheOutputTime([RespTime]) AS TheRespTime, 
     TheOutputTime([EndTime]) AS TheEndTime
    FROM 
     DaisyMSR;
    I presume this is suppose to have all gone in the same query? I must admit I've never heard of 'adding a function' :-)

    The report comes from a third party, who have the columns like this; Is it a big risk if there are spaces in the column names?

    You're knowledge is far superior to mine :-)!

    Thanks again

  8. #8
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    1) What error is it throwing up ?
    2) Have you saved the function using the Create Module ?
    3) If your table columns currently have spaces in them, then you will have to retain them in your query,
    like
    DaisyMSR.[Start Time],
    DaisyMSR.[End Time],

    Thanks

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

Similar Threads

  1. Excel Formula Needed in Access
    By bmschaeffer in forum Queries
    Replies: 4
    Last Post: 01-18-2012, 01:13 PM
  2. Replies: 5
    Last Post: 12-14-2011, 08:24 AM
  3. Replies: 0
    Last Post: 06-03-2011, 09:03 AM
  4. access query formula
    By simpleman in forum Queries
    Replies: 6
    Last Post: 11-26-2009, 09:13 AM
  5. Replies: 0
    Last Post: 09-03-2009, 01:58 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