MS Access Append Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hikosj
    New Member
    • Jun 2008
    • 2

    MS Access Append Record

    Hi all,

    I have a problem with a query in access that I cant seem to figure out. I have a form named frmRecruitment with a subform named sfrmParticipant . At the moment I am using an append query to append records from 'sfrmParticipan t' to 'frmInterventio n' using a button on a main form 'frmRecruitment '.

    This append query appends all the records from
    'sfrmParticipan t' to 'frmInterventio n' but I only want to append the record that is displayed as the current record in the form or the last record from tblParticipant into tblIntervention and by using the button on the form append only that very last record.

    This is what I have so far:
    Code:
    Private Sub Command31_Click()
    DoCmd.RunSQL "INSERT into [tblIntervention]([participantID]) VALUES (participantID)"
    End Sub
    
    Private Sub Command31_Click() DoCmd.RunSQL "INSERT into [tblIntervention]([participantID]) VALUES (participantID)" End Sub
    and yes it appends only the information being displayed or the very last record from tblParticipant into tblIntervention but it prompts me to enter the participantID in order to do it.

    How do I modify the append query to only append the form record with out promting me and having to enter the participant ID manually?


    Thanks for your help!
    hikosj
    Last edited by NeoPa; Jun 12 '08, 04:40 PM. Reason: [CODE] tags
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. Problem is that you are referring to participantID in the VALUES part of the string. If it is a local variable you will need to append its value to the string instead of including its name:

    Code:
    DoCmd.RunSQL "INSERT into [tblIntervention]([participantID]) VALUES ("  & participantID & ")"
    If participantID is a control on your form rather than a local variable you will need to use the me!participantI D syntax to refer to it. Either way, you cannot include its name in the string as the RunSQL command will not be able to interpret what it means - hence why it is asking you for a parameter value.

    if participantID is a field from another table (and not a control on your form or a local variable) you will need to obtain its value by using DLookup or somesuch, as again its value will not be available to runSQL simply by referring to its name the way you are doing at present.

    -Stewart

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      Please remember ALWAYS to use [ CODE ] tags whenever posting code on this site.

      Comment

      • hikosj
        New Member
        • Jun 2008
        • 2

        #4
        Originally posted by Stewart Ross Inverness
        Hi. Problem is that you are referring to participantID in the VALUES part of the string. If it is a local variable you will need to append its value to the string instead of including its name:

        Code:
        DoCmd.RunSQL "INSERT into [tblIntervention]([participantID]) VALUES ("  & participantID & ")"
        If participantID is a control on your form rather than a local variable you will need to use the me!participantI D syntax to refer to it. Either way, you cannot include its name in the string as the RunSQL command will not be able to interpret what it means - hence why it is asking you for a parameter value.

        if participantID is a field from another table (and not a control on your form or a local variable) you will need to obtain its value by using DLookup or somesuch, as again its value will not be available to runSQL simply by referring to its name the way you are doing at present.

        -Stewart
        I finally figured it out! It took me a while but I finally got it to work.
        > I added this to the click event of a button
        >
        >
        Code:
         Dim str As String
        > str = Form_frmPresentation.presentationID.Value
        > DoCmd.Close
        > DoCmd.OpenForm "sfrmAppointmentOne", acNormal, , , , acWindowNormal,
        > "Value=" + str
        >
        >
        > 'And then I added this to the on load event of the form getting the variable
        >
        > Form_frmIntervention.participantID.Value =
        > Form_frmParticipant.participantID.Value
        > Me.Refresh

        Comment

        Working...