Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Location
    Toronto
    Posts
    11

    Question Unanswered: Append to current record

    I'm using the folloing code in Sub to append y1, y2 and y3 values to ,
    Field1, Field2, and Field3 in table that have other fileds but want them to remain unchanged. But it looks like this code isn't working because there is no append. the fiels stay as 0. Please Any ideas??????

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("tblMytable")
    With rs
    .MoveLast
    .Edit
    !Field1 = y1

    !Field2 = y2

    !Fields = y3

    .Update

    .Close

    End With
    Set rs = Nothing

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Append to current record

    Originally posted by badr
    I'm using the folloing code in Sub to append y1, y2 and y3 values to ,
    Field1, Field2, and Field3 in table that have other fileds but want them to remain unchanged. But it looks like this code isn't working because there is no append. the fiels stay as 0. Please Any ideas??????

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("tblMytable")
    With rs
    .MoveLast
    .Edit
    !Field1 = y1

    !Field2 = y2

    !Fields = y3

    .Update

    .Close

    End With
    Set rs = Nothing
    As always, there are syntax differences between users but the syntax that I use differs slightly:

    With rs

    .Edit
    .Fields("Field1") = y1
    .Fields("Field2") = y2
    .Fields("Field3") = y3
    .Update

    End With

    If you are not getting any error messages and there are values contained in the variables y1, y2 and y3 then it should update the table to these values.

    Also, try opening the recordset as a dynaset type.

    Set rs = db.OpenRecordset("tblMytable", dbOpenDynaset)

    Gregg
    Last edited by basicmek; 12-15-03 at 16:00.

  3. #3
    Join Date
    Dec 2003
    Location
    Toronto
    Posts
    11
    thanks Gregg

  4. #4
    Join Date
    Dec 2003
    Location
    Budapest, HU
    Posts
    18
    Originally posted by badr
    thanks Gregg
    badr,

    I don't know if you have tried the code, but I'm afraid it won't append any record.

    To append a record you need to use:

    With rs
    .AddNew
    !Field1 = y1
    !Field2 = y2
    !Fields = y3
    .Update
    .Close
    End With

    You used MoveLast which moves the record pointer to the last EXISTING record, but does not append a new record.

  5. #5
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by TBÁrpi
    badr,

    I don't know if you have tried the code, but I'm afraid it won't append any record.

    To append a record you need to use:

    With rs
    .AddNew
    !Field1 = y1
    !Field2 = y2
    !Fields = y3
    .Update
    .Close
    End With

    You used MoveLast which moves the record pointer to the last EXISTING record, but does not append a new record.
    "... that have other fileds but want them to remain unchanged"

    He mentioned not wanting to change other values so I assumed that the record already contained data. You're right though append does refer to a new record.

    Gregg

Posting Permissions

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