Results 1 to 4 of 4
  1. #1
    mjd973 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2013
    Posts
    1

    Question Insert Recordset with conditional statement

    Hi everyone,



    I've been using access for several years and am working on a build to assign specific auditors to employees each month. Everything is complete except for one caveat which is each employee must have 4 audits complete once each month, but each must be done by a different auditor (i.e. an auditor can perform only one evaluation per employee). The trouble is I have not been able to find anyone who knows how to do this at work or any boards I have used online so far.

    Below is the ADO statement that I built:

    Sub AssignInvoicesToPersonnel()

    Dim rstStrat As DAO.Recordset, rstInvoices As DAO.Recordset
    Dim strSQL As String

    strSQL = "SELECT * FROM tblInvoices WHERE ReviewerID Is Null;"

    Set rstInvoices = CurrentDb.OpenRecordset(strSQL)

    If rstInvoices.RecordCount > 0 Then
    rstInvoices.MoveFirst

    strSQL = "SELECT * FROM tblStrat ORDER BY Rnd([Crew_ID]);"

    Set rstStrat = CurrentDb.OpenRecordset(strSQL)
    If rstStrat.RecordCount > 0 Then
    rstStrat.MoveFirst
    While Not rstInvoices.EOF

    rstInvoices.Edit
    rstInvoices!ReviewerID = rstStrat!CREW_ID
    rstInvoices.Update
    rstInvoices.MoveNext

    On Error Resume Next
    rstStrat.MoveNext
    On Error GoTo 0
    If rstStrat.EOF Then
    restStrat.MoveFirst
    End If

    Wend

    Else
    MsgBox "ERROR: There are no reviewers to assign to evals"
    End If

    rstStrat.Close
    Set rstStrat = Nothing
    Else
    MsgBox "There are ....
    End If

    rstIncoices.Close
    Set rstInvoices = Nothing

    End Sub"


    For the statement above, my "tblInvoices" has a field titled "Employee_Name" and what I want to do is add a statement that says when updating the next Employee Name field with a Reviewer Id, if that same Reviewer Id has already been assigned to a previous evalulation for the same Employee Name, then to skip to another Reviewer Id. Does that make sense?

    Thank you in advance for any help!!!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You open a recordset on reviewers, right? At the point of assigning, use a DCount() to test for the reviewer/employee combination in the last month. If greater than 0, move to the next and test again.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Calculating data based on value in other records of same table is tricky. You need to do a search of the table to determine if the Reviewer ID is already associated with a record that meets criteria. Can probably be done with a domain aggregate like DLookup.

    Why are you updating tblInvoices with reviewerID? This is an audit of invoices? Employees are associated with invoices? So reviewer cannot review invoice with employee that reviewer has already reviewed that month? What is tblStrat data?
    Last edited by June7; 04-29-2013 at 10:34 AM.
    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.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Below is the ADO statement that I built:
    What makes you think you have written ADO ?

    You have specifically Dimmed DAO.Recordsets

    The trouble is I have not been able to find anyone who knows how to do this at work or any boards I have used online so far.
    It isn't clear, as June7's questions show, that your terminology is consistent. Perhaps you could clarify for the reader the meaning of
    Crew_ID
    Reviewer
    Evals
    Invoice
    and how these things are related.

    Telling/Asking the reader in plain English is often a great way to focus on the issue/opportunity to be resolved. Once reader's understand your situation, often many options will evolve.

    Adding vba code of HOW you have done something to a confusing textual description is masking the underlying issue.

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

Similar Threads

  1. Insert into table from recordset
    By Colargol in forum Programming
    Replies: 2
    Last Post: 12-10-2011, 06:43 PM
  2. DoCMD Insert Query Conditional
    By svcghost in forum Queries
    Replies: 5
    Last Post: 11-05-2010, 11:06 AM
  3. Conditional Programming within a recordset
    By Bmw in forum Programming
    Replies: 2
    Last Post: 09-27-2010, 07:11 AM
  4. Conditional Select Statement
    By shexe in forum Queries
    Replies: 4
    Last Post: 09-22-2010, 09:10 AM
  5. Replies: 3
    Last Post: 02-16-2010, 10:43 PM

Tags for this Thread

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