I'm sort of new to Access and I'm having some trouble understanding when to use queries vs. recordsets vs. SQL etc. to update table data.
I'm building a database that will include tabbed pages with linked subforms on each page. The subforms are based on (multi-table) underlying queries, which I assumed would then update the corresponding underlying tables as the user input form data. Is this right?
But it doesn't end there... I also must integrate code which will capture an autonumber from the mainform and display it on a subform, as well as update it to the (subform) table as a foreign key when the record is saved. Then I must do the opposite: save the subform (table) autonumber to the mainform table? Is this even possible?
For the 1st scenario, I tried using the code below (to no avail):
Private Sub btnSaveProp_Click()
On Error GoTo Err_btnSaveProp_Click
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL, strFldData As String
'capture subform data
strFldData = Str(Me![PropID])
'not sure about the following syntax but I only
'want to insert into 1 data field & the whole
'record is huge so I only selected necessary data
strSQL = "SELECT JobID, PropDetailID FROM
Jobs WHERE JobID = " & Str(Me.Parent![JobID])
'can i execute 2 different sql statements? how?
strSQL2 = "INSERT INTO Jobs (PropDetailID) Values
strFldData)"
If Not IsNull(JobID) Then
Set db = CurrentDb.OpenRecordset(strSQL)
Else
MsgBox "There was a problem adding data"
End If
rs.Close .
Exit_btnSaveProp_Click:
Set rs = Nothing 'Deassign all objects.
Set db = Nothing
Exit Sub
Err_btnSaveProp_Click:
Resume Exit_btnSaveProp_Click
End Sub
How do you integrate a SQL statement with a form/underlying-query modification? I know I've got this all mixed up somewhere, can anybody help me get straightened out? Thanks for any help you can give.
I'm building a database that will include tabbed pages with linked subforms on each page. The subforms are based on (multi-table) underlying queries, which I assumed would then update the corresponding underlying tables as the user input form data. Is this right?
But it doesn't end there... I also must integrate code which will capture an autonumber from the mainform and display it on a subform, as well as update it to the (subform) table as a foreign key when the record is saved. Then I must do the opposite: save the subform (table) autonumber to the mainform table? Is this even possible?
For the 1st scenario, I tried using the code below (to no avail):
Private Sub btnSaveProp_Click()
On Error GoTo Err_btnSaveProp_Click
Dim db As Database
Dim rs As DAO.Recordset
Dim strSQL, strFldData As String
'capture subform data
strFldData = Str(Me![PropID])
'not sure about the following syntax but I only
'want to insert into 1 data field & the whole
'record is huge so I only selected necessary data
strSQL = "SELECT JobID, PropDetailID FROM
Jobs WHERE JobID = " & Str(Me.Parent![JobID])
'can i execute 2 different sql statements? how?
strSQL2 = "INSERT INTO Jobs (PropDetailID) Values
strFldData)"
If Not IsNull(JobID) Then
Set db = CurrentDb.OpenRecordset(strSQL)
Else
MsgBox "There was a problem adding data"
End If
rs.Close .
Exit_btnSaveProp_Click:
Set rs = Nothing 'Deassign all objects.
Set db = Nothing
Exit Sub
Err_btnSaveProp_Click:
Resume Exit_btnSaveProp_Click
End Sub
How do you integrate a SQL statement with a form/underlying-query modification? I know I've got this all mixed up somewhere, can anybody help me get straightened out? Thanks for any help you can give.