I have a Visual Basic Form that has a multi-tab format. The first tab is where all the student information is entered. The student information is kept in a table called tblStudentLog. The primary key is an Autonumber called [StudentLogNo]. The five remaining tabs have information stored in a separate table called tblLog. TblLog has an Autonumber too as a primary Key called LogNo.
When I click the Save button on the VB form, I want to save the StudentLogNo, an Autonumber and Primary Key, to BOTH the tblStudentLog and tblLog tables.
Here's a code snippet:
Private Sub cmdSave_Click()
Dim rs As DAO.Recordset
Set rs = dbWrap.OpenRecordset("tblStudentLog", dbOpenTable)
With rs
.AddNew
If txtStudentNo.Text <> "" Then
.Fields("StudentNo" = txtStudentNo.Text
End If
If dtpDateLog.Value <> "" Then
.Fields("Date" = dtpDateLog.Value
End If
If txtStaffNo.Text <> "" Then
.Fields("StaffNo" = Suser
End If
If cboSchool.Text <> "" Then
.Fields("SchoolNo" = cboSchool.ItemData(cboSchool.ListIndex)
End If
If txtGrade.Text <> "" Then
.Fields("Grade" = txtGrade.Text
End If
If txtComment.Text <> "" Then
.Fields("Comment" = txtComment.Text
End If
If txtGAFScore.Text <> "" Then
.Fields("GAF" = txtGAFScore.Text
End If
If txtAmountOfTime.Text <> "" Then
.Fields("AmtOfTime" = txtAmountOfTime.Text
End If
.Update
End With
Call AddJuvJust
Call AddPF
Call AddRF
Call AddRefReasons
Call AddRefSources
Call AddWRT
Call AddInt
MsgBox "Save successful!", vbInformation
Unload frmSearch
Unload Me
End Sub
Private Sub AddJuvJust()
Dim rsAddLog As DAO.Recordset
Dim I As Integer
Dim sCatID
Set rsAddLog = dbWrap.OpenRecordset("tblLog", dbOpenTable)
With rsAddLog
For I = 1 To tvwAddJuvJust.Nodes.Count
sCatID = Right(tvwAddJuvJust.Nodes.Item(I).Key, Len(tvwAddJuvJust.Nodes.Item(I).Key) - 2)
.AddNew
.Fields("StudentNo" = txtStudentNo.Text
'====>Here is where I want to add the StudentLogNo
.Fields("StaffNo" = txtStaffNo.Text
.Fields("SchoolNo" = cboSchool.ItemData(cboSchool.ListIndex)
.Fields("CatID" = sCatID
.Fields("CatNo" = 13
.Fields("Date" = dtpDateLog.Value
.Update
Next I
End With
rsAddLog.Close
Set rsAddLog = Nothing
End Sub
When I click the Save button on the VB form, I want to save the StudentLogNo, an Autonumber and Primary Key, to BOTH the tblStudentLog and tblLog tables.
Here's a code snippet:
Private Sub cmdSave_Click()
Dim rs As DAO.Recordset
Set rs = dbWrap.OpenRecordset("tblStudentLog", dbOpenTable)
With rs
.AddNew
If txtStudentNo.Text <> "" Then
.Fields("StudentNo" = txtStudentNo.Text
End If
If dtpDateLog.Value <> "" Then
.Fields("Date" = dtpDateLog.Value
End If
If txtStaffNo.Text <> "" Then
.Fields("StaffNo" = Suser
End If
If cboSchool.Text <> "" Then
.Fields("SchoolNo" = cboSchool.ItemData(cboSchool.ListIndex)
End If
If txtGrade.Text <> "" Then
.Fields("Grade" = txtGrade.Text
End If
If txtComment.Text <> "" Then
.Fields("Comment" = txtComment.Text
End If
If txtGAFScore.Text <> "" Then
.Fields("GAF" = txtGAFScore.Text
End If
If txtAmountOfTime.Text <> "" Then
.Fields("AmtOfTime" = txtAmountOfTime.Text
End If
.Update
End With
Call AddJuvJust
Call AddPF
Call AddRF
Call AddRefReasons
Call AddRefSources
Call AddWRT
Call AddInt
MsgBox "Save successful!", vbInformation
Unload frmSearch
Unload Me
End Sub
Private Sub AddJuvJust()
Dim rsAddLog As DAO.Recordset
Dim I As Integer
Dim sCatID
Set rsAddLog = dbWrap.OpenRecordset("tblLog", dbOpenTable)
With rsAddLog
For I = 1 To tvwAddJuvJust.Nodes.Count
sCatID = Right(tvwAddJuvJust.Nodes.Item(I).Key, Len(tvwAddJuvJust.Nodes.Item(I).Key) - 2)
.AddNew
.Fields("StudentNo" = txtStudentNo.Text
'====>Here is where I want to add the StudentLogNo
.Fields("StaffNo" = txtStaffNo.Text
.Fields("SchoolNo" = cboSchool.ItemData(cboSchool.ListIndex)
.Fields("CatID" = sCatID
.Fields("CatNo" = 13
.Fields("Date" = dtpDateLog.Value
.Update
Next I
End With
rsAddLog.Close
Set rsAddLog = Nothing
End Sub