Results 1 to 4 of 4
  1. #1
    adams77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    16

    Update a query with date

    Is it possible to run a report that would update a query with the day the report was ran? If so, The next time the report was ran it would not update the field that already had a date.



    If this could be done, would you give me some direction.

    Thank you in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Code behind a form that opens report can update data. Code behind report can update data.

    The real trick is figuring out what event to put code into. Maybe the report Close event.

    Which table, which field, which records?
    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
    adams77 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    16
    by chance do you have any sample code for this?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    An example from my db:
    Code:
    Private Sub Report_Close()
    'save calculated results to ApprovedFurnaceCalibrations table
    'and open FurnaceCalibrationFactors report
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Set cn = CurrentProject.Connection
    Set rs = New ADODB.Recordset
    rs.Open "SELECT Furnace, MixNumber, RRound([Avg12]-[ASPHOPT],2) AS CF " & _
    "FROM 610 RIGHT JOIN FurnaceCalibrationReportData ON [610].LABNUM = FurnaceCalibrationReportData.MixNumber " & _
    "WHERE Not Avg12 Is Null;", cn, adOpenStatic, adLockPessimistic
    If Not IsNull(DLookup("MixDesignNum", "ApprovedFurnaceCalibrations")) Then
        If MsgBox("Correction Factors already recorded. Update all values?", vbYesNo, "CF") = vbYes Then
            CurrentDb.Execute "DELETE FROM ApprovedFurnaceCalibrations WHERE MixDesignNum='" & Me.MixNumber & "'"
        End If
    End If
    If IsNull(DLookup("MixDesignNum", "ApprovedFurnaceCalibrations", "FurnaceID='" & rs!Furnace & "' AND MixDesignNum='" & Me.MixNumber & "'")) Then
        While Not rs.EOF
            CurrentDb.Execute "INSERT INTO ApprovedFurnaceCalibrations(FurnaceID, MixDesignNum, CF) VALUES ('" & rs!Furnace & "', '" & Me.MixNumber & "', " & rs!cf & ")"
            rs.MoveNext
        Wend
    End If
    ExitProc:
    rs.Close
    DoCmd.OpenReport "FurnaceCalibrationFactors", acViewPreview
    CurrentDb.Execute "DELETE * FROM FurnaceCalibrationReportData"
    End Sub
    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. Need to use an update query on date string field
    By clawschieff in forum Queries
    Replies: 2
    Last Post: 01-28-2014, 02:07 PM
  2. Update Query based on existing date
    By axdxnco in forum Queries
    Replies: 1
    Last Post: 06-12-2013, 02:15 PM
  3. Date Conversion through Update Query
    By Steven.Allman in forum Queries
    Replies: 8
    Last Post: 01-30-2013, 01:38 PM
  4. query to update a date based on another date
    By tkendell in forum Access
    Replies: 3
    Last Post: 06-29-2011, 09:32 PM
  5. date selection update query
    By mountainwombat in forum Queries
    Replies: 2
    Last Post: 06-07-2011, 09:29 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