Results 1 to 9 of 9
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Append Query For Single Record

    How can I make my append query use the selected record from my form? I don't want to do a everything, i.e. all records append.
    This code fires on the click event, it is a checkbox. The append query which is named Qappendtoregister has NO criteria. Primary Key for table form is based on is EventID and Primary Key to table where data is going to is RegID .

    Private Sub enter_Click()
    DoCmd.Beep


    If Me.Dirty Then Me.Dirty = False
    DoCmd.SetWarnings False 'Purpose: Append Scheduled Event To Check Register.
    DoCmd.OpenQuery "Qappendtoregister"
    DoCmd.RunCommand acCmdSaveRecord
    If Me.Dirty Then Me.Dirty = False
    DoCmd.SetWarnings True
    End Sub



    If I use this code in the query, will it only then use one single record and only use the single records ID? What then when I want to do multiple records?

    [Forms]![frmEvent]![EventID]
    Last edited by burrina; 01-04-2013 at 02:20 PM. Reason: Code in Query

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Show the sql statement for Qappendtoregister.
    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
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    INSERT INTO TReg ( EventID, Bank, EventStart, BalDate, Payee, FreqPayee, frequencyamount, Debit, credit, ChkNo, TransType, PeriodTypeID, [Memo] )
    SELECT tblEvent.EventID, tblEvent.Bank, tblEvent.EventStart, tblEvent.MYDte, tblEvent.Payee, tblEvent.FreqPayee, tblEvent.FrequencyAmnt, tblEvent.Debit, tblEvent.credit, tblEvent.ChkNo, tblEvent.TransType, tblEvent.PeriodTypeID, tblEvent.Comment
    FROM tblEvent
    WHERE (((tblEvent.EventID)=[Forms]![frmEvent]![EventID]));

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That looks correct. Only the one record identified by the unique EventID should be retrieved and inserted.
    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.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    So if I wanted to do all records, then? Where enter = true and nextschddte = Date() Then what would I do, anything different?

    The ALL records is what throws me. Maybe do a separate IF Statement and use a different command button or checkbox? That should work huh?
    DoCmd.RunCommandSelectAllRecords or something like that ?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I would not use a query object. I would build the sql statement in VBA then run the statement with CurrentDb.Execute.
    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.

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    So, your saying instead of my append query run this: Is this syntax correct? I have never tried DB.Execute or using any sql ! Use on the OnClickEvent?

    CurrentDb.Execute

    INSERT INTO TReg ( EventID, Bank, EventStart, BalDate, Payee, FreqPayee, frequencyamount, Debit, credit, ChkNo, TransType, PeriodTypeID, [Memo] )
    SELECT tblEvent.EventID, tblEvent.Bank, tblEvent.EventStart, tblEvent.MYDte, tblEvent.Payee, tblEvent.FreqPayee, tblEvent.FrequencyAmnt, tblEvent.Debit, tblEvent.credit, tblEvent.ChkNo, tblEvent.TransType, tblEvent.PeriodTypeID, tblEvent.Comment
    FROM tblEvent
    WHERE (((tblEvent.EventID)=[Forms]![frmEvent]![EventID]));


    So, if i ran this would it then use as a single record or could I somehow if I wanted use a select all to do a batch process? Single is a good option to keep but I see situations where a select all could be used.
    Last edited by burrina; 01-04-2013 at 04:48 PM. Reason: Question.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Code:
    Dim strFilter As String
    
    Select Case Me.Combo63
    Case "Today"
    strFilter = " WHERE ..."
    ...
    Case "All"
    strFilter = ""
    End Select
    
    CurrentDb.Execute "INSERT INTO TReg (EventID, Bank, EventStart, BalDate, Payee, FreqPayee, frequencyamount, Debit, credit, ChkNo, TransType, " & _
    "PeriodTypeID, [Memo]) SELECT EventID, Bank, EventStart, MYDte, Payee, FreqPayee, FrequencyAmnt, Debit, credit, ChkNo, TransType, PeriodTypeID, Comment " & _
    "FROM tblEvent " & strFilter
    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.

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Thank You.

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

Similar Threads

  1. Append Query Creates a New Record
    By burrina in forum Queries
    Replies: 5
    Last Post: 01-01-2013, 07:27 PM
  2. Append Query For Single Record
    By burrina in forum Queries
    Replies: 3
    Last Post: 12-30-2012, 11:23 PM
  3. Query record set into single excel row
    By bruegel in forum Queries
    Replies: 10
    Last Post: 07-09-2012, 08:20 AM
  4. append query without duplicate record
    By smahdih in forum Queries
    Replies: 5
    Last Post: 11-16-2011, 12:29 AM
  5. Single Record Update Query from a Form
    By Steven.Allman in forum Access
    Replies: 0
    Last Post: 03-30-2011, 09:34 AM

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