Results 1 to 8 of 8
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    using a specific query depending on a date range

    Hey guys,

    So close to being done with this stage of the project.

    What kind of code/query can I do to do the following:

    If the date being used to enter data on (selected via combobox on main form) is in the range of Quarter "X", then use the value of [QrtlyAvg] from query Quarter "X-1".

    Obviously I can do a DLookup to get the value from the query, but how can I get the program to chose the right query. The 4 options are SlspInfo_Q1, SlspInfo_Q2, SlspInfo_Q3, SlspInfo_Q4.

    When a salesperson uses sick or vacation time, we multiply their hours by the quarterly average from the previous quarter. This value needs to get pulled in to the input form where hours, commission, etc gets typed in.



    Was I detailed enough?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I recommend some vba code, probably Select Case construct
    see

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Hmm, I guess I could use that and pretty much say that if the date is within Q4, use Q3 avg; if within Q3, use Q2 avg, etc...

    I'll give this a go tonight or tomorrow.

  4. #4
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Ok what is wrong with this statement:

    Code:
    Me.HourlyRate = DLookup("HrlyAvg", "SlspInfo_Q3_2", "Employee= " & "Me!Text34")
    me.hourlyrate is an unbound textbox on the entry form
    HrlyAvg is a field in the query SlspInfo_Q3_2
    Employee is a field in the same query, formatted as text
    me!text34 is a textbox on the entry form that pulls the employee code, in the format of AB12345, formatted as text.

    I am getting run-time error 2471: the expression produced this error:'me!text34'

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You do not need quotes around
    "Me!Text34"

    Since Employee is string, I think you need

    Me.HourlyRate = DLookup("HrlyAvg", "SlspInfo_Q3_2", "Employee= '" & Me!Text34 & "'")

  6. #6
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Quote Originally Posted by orange View Post

    Me.HourlyRate = DLookup("HrlyAvg", "SlspInfo_Q3_2", "Employee= '" & Me!Text34 & "'")
    Ah that's what I missed. I'm playing hooky today, but I'll make this change on Monday.

    Appreciate it orange!

  7. #7
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Works great! Thanks orange!

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

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

Similar Threads

  1. Selecting from specific Date and Time range
    By LindaRuble in forum Programming
    Replies: 1
    Last Post: 05-15-2013, 07:37 AM
  2. Replies: 3
    Last Post: 05-03-2013, 09:03 AM
  3. Replies: 25
    Last Post: 11-16-2012, 12:47 PM
  4. SELECT a specific DATE RANGE in Query
    By taimysho0 in forum Queries
    Replies: 28
    Last Post: 06-04-2012, 04:58 PM
  5. Replies: 2
    Last Post: 09-18-2011, 03:45 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