Save Button VBA Coding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, can someone help me with this? Im trying to put a save button on a bottom
of a data entry form. So only when the user clicks on the save button, the
record is written into the database.

So far, I created another temp table to store the data for the form and
append it to the main database when the save button is clicked. But Whenever
I click on the save button, the form will go to a new record although the
saving works perfectly. Is there a better solution to do this saving
function? The database seems to grow in size rather quickly with the
inserting and deleting of temp data.

Heres my code for the save button.

If mbRequireSave Or Me.Dirty Then
DoCmd.Requery
DoCmd.SetWarnings False

If IsNull(DLookup("ReportID", "9000_Data", "[ReportID] = '" &
Me.txtReportID & "'")) Then
DoCmd.RunSQL "INSERT INTO [9000_Data] SELECT [9000_DataEntry].*
FROM [9000_DataEntry] WHERE [ReportID] = '" & Me.ReportID & "'"
End If

DoCmd.SetWarnings True
mbRequireSave = False
Else
MsgBox "Record Exist in Database."
End If
 
Hello Airkon.
Hi, can someone help me with this? Im trying to put a save button on a
bottom of a data entry form. So only when the user clicks on the save
button, the record is written into the database.

So far, I created another temp table to store the data for the form
and append it to the main database when the save button is clicked.
But Whenever I click on the save button, the form will go to a new
record although the saving works perfectly.

Don't requery the form, just "RunCommand acCmdSaveRecord".
Is there a better solution to do this saving function? The database
seems to grow in size rather quickly with the inserting and deleting
of temp data. [...]

Why use a temp table? Use unbound controls on an unbound form.
You can either assemble an "insert into ... values" statement with the
values of the controls or use the AddNew method of a recordset object to
append the new record.
 
Back
Top