Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with the addnew and update methods of the data control...

Status
Not open for further replies.

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.
 
you Take 3 x With frmMain.dataMain.Recordset !! with 3 Tables (of recordsets) !!

Not good Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
I am new to database programming so I may be wrong, but it was my understanding you could have multiple tables in a database (3 in my case). Now, before calling these procedures, I change the table that the data control is currently set on to the appropriate table to add a record to it. If I'm wrong, please tell me and how to get this to work. Thank you! :)
 
if it is a little project send me the project in a .zip file also the database and i explain with comments what you are to do

Eric
Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top