I've been coding in VBA for over a year now but I haven't really dug into recordsets and handling databases as objects too much. From what I have read DAO seems to be the most appropriate for my use, but that's the most I've been able to grasp on the subject.
What I am trying to accomplish is to take a single record from a table (which has hours worked on an RMA), put the record data into a popup form that allows the user to edit the data and hours and either save the changes or cancel.
I am slightly confused as to how a recordset will act. I set a DAO.Database object then opened a recordset with a select/where statement. Now with the form acting on the single record in the recordset, if I commit changes made in the form to the recordset, can I commit those changes back into the table? How would I go about doing that? I don't need any specific code, just some ideas or tips and general information on how recordsets work and act. Links to articles are great also.
Here's what I have so far:
Assuming that I use this recordset as the source, all the textboxes on the form would be bound to the fields from the recordset.
Obviously if the user hits the cancel button, the form closes and does not commit any changes to the record. But if the user clicks save, it would verify the data, and commit the changes. How should the changes be committed? Is that something done through a recordset or do I have to execute an update statement to set all the current data in the recordset to the entry in the tblRMALabor where the ID matches?
What I am trying to accomplish is to take a single record from a table (which has hours worked on an RMA), put the record data into a popup form that allows the user to edit the data and hours and either save the changes or cancel.
I am slightly confused as to how a recordset will act. I set a DAO.Database object then opened a recordset with a select/where statement. Now with the form acting on the single record in the recordset, if I commit changes made in the form to the recordset, can I commit those changes back into the table? How would I go about doing that? I don't need any specific code, just some ideas or tips and general information on how recordsets work and act. Links to articles are great also.
Here's what I have so far:
Code:
Private Sub Form_Load()
'Check for OpenArgs
If Not IsNull(OpenArgs) Then
Dim intRecordID As Integer
'Check to make sure that OpenArgs is numeric.
If !IsNumeric(OpenArgs) Then
MsgBox "Openargs is not a numeric value. Ending macro and closing form."
DoCmd.Close
End If
intRecordID = OpenArgs
MsgBox "RecordID read as: " & intRecordID
'Close if no OpenArgs
Else
MsgBox "Openargs is null. No data loaded. Now closing form."
DoCmd.Close
End If
'Open recordset from OpenArgs ID
Dim strSQLGetID As String
strSQLGetID = "SELECT * FROM tblRMALabor WHERE ID = " & intRecordID
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
rs = db.OpenRecordset(strSQLGetID, dbOpenDynaset) 'Not sure what other options to specify here, if any
'Anything else here???
End Sub
Assuming that I use this recordset as the source, all the textboxes on the form would be bound to the fields from the recordset.
Obviously if the user hits the cancel button, the form closes and does not commit any changes to the record. But if the user clicks save, it would verify the data, and commit the changes. How should the changes be committed? Is that something done through a recordset or do I have to execute an update statement to set all the current data in the recordset to the entry in the tblRMALabor where the ID matches?