Guest_imported
New member
- Jan 1, 1970
- 0
I can't seem to get this to work well, my code works 1 out of 3 times. The objective is to add a record to a recordset of a database. I know this is really simple and that I'm probably doing something stupid, but I'm tired of trying to debug this my self, so here is a sample of my code.
(I have code resetting the database to the appropriate recordset before the these procedures are executed.)
**Working Code**
Public Sub AddClass(strName As String, strLength, Semesters, strSections As String, strGroup)
With frmMain.dataMain.Recordset
.AddNew
!Class = strName
!Length = strLength
!Semesters = Semesters
!sections = strSections
!Group = strGroup
.Update
End With
End Sub
Now this works well, but these other two samples of code are a headache...
**Buggy Samples**
Public Sub AddTeacher(strName As String, strMainroom As String, Traveling, Classes)
With frmMain.dataMain.Recordset
.AddNew
!Teacher = strName
!MainRoom = strMainroom
!Traveling = Traveling
!Classes = Classes
.Update
End With
End Sub
And the other one...
Public Sub AddRoom(strRoom As String, Used, Classes, strTeacher As String)
With frmMain.dataMain.Recordset
.AddNew
!Room = strRoom
!Used = Used
!Classes = Classes
!Teacher = strTeacher
.Update
End With
End Sub
Now, the problem is when these are executed, it generates an error 3020, or "Update or CancelUpdate without AddNew or Edit. I've done many things to try to solve this problem but to now avail. I also would like to find out why the one set of code is working and not the other 2, they're almost identical. Thank you for your time in reading this and the time you take to help me if you choose to.
(I have code resetting the database to the appropriate recordset before the these procedures are executed.)
**Working Code**
Public Sub AddClass(strName As String, strLength, Semesters, strSections As String, strGroup)
With frmMain.dataMain.Recordset
.AddNew
!Class = strName
!Length = strLength
!Semesters = Semesters
!sections = strSections
!Group = strGroup
.Update
End With
End Sub
Now this works well, but these other two samples of code are a headache...
**Buggy Samples**
Public Sub AddTeacher(strName As String, strMainroom As String, Traveling, Classes)
With frmMain.dataMain.Recordset
.AddNew
!Teacher = strName
!MainRoom = strMainroom
!Traveling = Traveling
!Classes = Classes
.Update
End With
End Sub
And the other one...
Public Sub AddRoom(strRoom As String, Used, Classes, strTeacher As String)
With frmMain.dataMain.Recordset
.AddNew
!Room = strRoom
!Used = Used
!Classes = Classes
!Teacher = strTeacher
.Update
End With
End Sub
Now, the problem is when these are executed, it generates an error 3020, or "Update or CancelUpdate without AddNew or Edit. I've done many things to try to solve this problem but to now avail. I also would like to find out why the one set of code is working and not the other 2, they're almost identical. Thank you for your time in reading this and the time you take to help me if you choose to.