Consulting

Results 1 to 13 of 13

Thread: need help with a query or two

  1. #1
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location

    need help with a query or two

    okay I need some help.. I am new here and fairly new to access..

    I'll start with two tables

    tblEmployees & tblMetrics

    I have a report and a query as well...

    The query pulls the data using the folowing criteria

    >=DateAdd("d",-5,[Forms]![RUI]![ddate]) And <=[Forms]![RUI]![ddate]

    This returns what I want (the last 5 days of data for each employee)...

    I need to further scrutinize the data so that the query will only report out if data exists on the data specified on the form, if it does the run the dateadd portion..

    any suggestions would be greatly appreciated

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I'm a little unsure what you mean.

    Do mean that the query will only run if a value is placed in ddate on the RUI form?

  3. #3
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    if a user enters 6/25/05 in the form, I need to the query to first check if data exists for 6/25/05 for that employee... if it does then do the dateadd function.

    However if data does not exist for 6/25/05 then do not report anything for that employee..


    Hope this helps explain it better

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    How are you opening the query/report from the form?

    Are you using a button?

    If you where you could use DCount to find out if any records existed for the date and then open/not open the query/report as appropriate.

  5. #5
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    I am using a button from the form to open the report, which launches the query...

    I have tried some DCount things but I'm afraid I just didn't understand the concept enough to apply it accordingly

  6. #6
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    here is what I tried....

    [VBA]
    Dim stDocName As String
    stDocName = "Agent Level Daily Report (Standard)"

    If DCount("[METID]", "Agent Level Daily Report Query (Current)", "[RPTD] = #" & Me!ddate & "#") = 0 Then
    MsgBox "no records match", vbOKOnly
    Else
    DoCmd.OpenReport stDocName, acPreview
    End If
    [/VBA]

    But when I run it I get an error " you cancelled the previous operation"

  7. #7
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Do you have any code behind the buttons?

    DCount is explained pretty well in Access help.

    I can't give you a specific example as I don't know your exact data structure or field names

  8. #8
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    here is the entire code.. I uncommented the DCount Section to show... I commented the plain docmd so as to not conflict

    [VBA]
    Private Sub AgentDailyReports_Click()
    On Error GoTo Err_DailyReports_Click
    Dim stDocName As String
    stDocName = "Agent Level Daily Report (Standard)"

    If DCount("[METID]", "Agent Level Daily Report Query (Current)", "[RPTD] = #" & Me!ddate & "#") = 0 Then
    MsgBox "no records match", vbOKOnly
    Else
    DoCmd.OpenReport stDocName, acPreview
    End If

    ' DoCmd.OpenReport stDocName, acPreview
    Exit_DailyReports_Click:
    Exit Sub
    Err_DailyReports_Click:
    MsgBox Err.Description
    Resume Exit_DailyReports_Click

    End Sub
    [/VBA]

  9. #9
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    That looks fine to me.

    What's the error?

  10. #10
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    "you cancelled the previous operation"

  11. #11
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    You getting an error on DCount or DoCmd?

  12. #12
    VBAX Regular dvenn's Avatar
    Joined
    Jun 2005
    Posts
    41
    Location
    honestly I don't know how to determine that... suggestions?

  13. #13
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Add the command stop at the beginning of the procedure and hit F8 once you've reached the breakpoint to move forward one line at a time. Pay attention to when it jumps to your error handler. The line it jumps from is the one causing the error.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •