ms access vba code to save record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geniussupreme
    New Member
    • Jul 2008
    • 2

    ms access vba code to save record

    hi guys need your help.

    im trying to save a record to another table.

    this is how it supposed to work...

    form1 (table_A) contains NameID, Age and other personal details.
    once clicked on the save button the form1 (table_A) contents will save as usual all the fields displayed on the form and the NameID and Age field values will be saved (again) to table_B.

    can someone show me the right method to do this?
  • geniussupreme
    New Member
    • Jul 2008
    • 2

    #2
    Originally posted by geniussupreme
    hi guys need your help.

    im trying to save a record to another table.

    this is how it supposed to work...

    form1 (table_A) contains NameID, Age and other personal details.
    once clicked on the save button the form1 (table_A) contents will save as usual all the fields displayed on the form and the NameID and Age field values will be saved (again) to table_B.

    can someone show me the right method to do this?
    this code
    DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    saves the record to the current table the form is linked to right? what if i want to save certain field values to another table that is not linked to?

    Comment

    • salimudheen
      New Member
      • Jan 2007
      • 14

      #3
      U keep the following method to save record,
      In Table_A, the NameId as Autonumber, In Table_B, the NameId as Number.
      For each save in form_1, the bounded table Table_A is automatically saved. After that u should write the code for save the record to Table_B.
      dim lngId as long
      dim strSql as string

      lngId=DLOOKUP(" NameId","Table_ B","NameId=" & Me.NameId)

      if lngId > 0 then
      strSql= "Update Table_B set NameId=lngId, ......."
      currentdb.execu te strSql
      else
      strSql= "Insert into Table_B(NameId, Fld2,....) values(Me.NameI d,val,...)"
      currentdb.execu re strSql
      end if

      Comment

      Working...