pangeh@hotmail.co.uk
New member
- Local time
- Today, 14:18
- Joined
- Dec 7, 2009
- Messages
- 9
Hi,
I'm new to this forum and require some help with an access db I cant get to work.
I have two different tables student records and siblings. I have an add new record fom that goes to a new blank record and when you press save it searches the latest record number then assigns a new one by incrementing the last number.
This forms source is the students record table.
I have some unbound controls on the form and I want the values of these controls to be added as a new record to the fields of the tblsiblings table.
To do this I have used ado in vba. However when ever i run the program I get an "object variable or with block variable not set". When going to debug it highlights the source part of my ado code. However the sql I am using to get the new table looks ok, I tried it in a query and it was fine.
The code I am using is as follows:
Any assistance would be greatly appreciated.
Kind Regards
Pangeh
I'm new to this forum and require some help with an access db I cant get to work.
I have two different tables student records and siblings. I have an add new record fom that goes to a new blank record and when you press save it searches the latest record number then assigns a new one by incrementing the last number.
This forms source is the students record table.
I have some unbound controls on the form and I want the values of these controls to be added as a new record to the fields of the tblsiblings table.
To do this I have used ado in vba. However when ever i run the program I get an "object variable or with block variable not set". When going to debug it highlights the source part of my ado code. However the sql I am using to get the new table looks ok, I tried it in a query and it was fine.
The code I am using is as follows:
Code:
Dim rst_sibs As ADODB.Recordset
Dim sql_sibs As String
Dim sibs As String
Dim sibnum As Integer
Dim sib1 As String
Dim sib2 As String
Dim sib3 As String
Dim sib4 As String
Dim sib5 As String
sibs = [Siblings].Value
sibnum = [Number of siblings].Value
sib1 = [Sibling 1].Value
sib2 = [Sibling 2].Value
sib3 = [Sibling 3].Value
sib4 = [Sibling 4].Value
sib5 = [Sibling 5].Value
sql_sibs = "SELECT tblSiblings.[Student ID], tblSiblings.Siblings, tblSiblings.[Sibling 1], tblSiblings.[Sibling 2]," & _
"tblSiblings.[Sibling 3], tblSiblings.[Sibling 4], tblSiblings.[Sibling 5], tblSiblings.[Number of siblings]FROM tblSiblings"
Set tst_sibs = New ADODB.Recordset
With rst_sibs
.Source = sql_sibs
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
End With
rst_sibs.AddNew
rst_sibs.Fields("Siblings") = sibs
rst_sibs.Fields("Number of siblings") = sibnum
rst_sibs.Fields("Sibling 1") = sib1
rst_sibs.Fields("Sibling 2") = sib2
rst_sibs.Fields("Sibling 3") = sib3
rst_sibs.Fields("Sibling 4") = sib4
rst_sibs.Fields("Sibling 5") = sib5
rst_sibs.Fields("Student ID") = new_student_id
rst_sibs.Update
rst_sibs.Close
DoCmd.save
DoCmd.Close
Any assistance would be greatly appreciated.
Kind Regards
Pangeh