Click to See Complete Forum and Search --> : problems with AddNew method - cant get code right?/|#!
Paul Dudley
Mar 14th, 2000, 03:46 PM
I'm trying to write code to add a new record to a form with a text box on it . Once the user clicks the Total text box a message comes up stating that they "must start a new invoice peroid now". I want to add some code following clicking O.K to this message that will automatically start a new record. I keep getting errors like recordset not defined. Can somebody give me some directions please?
The database is called Selecttest2
The table is called Mailing List
Regards Paul
Wesam
Mar 16th, 2000, 02:45 PM
Hi,
Try the following:
- Insert a module.
- In the module type the following:
Dim Db As Database.
Dim Rec As RecordSet.
- In the forms Form_Load() event, type the following:
Set Db=DbEngine.WorkSpaces(0)._
OpenDatabase("Selecttest2.mdb")
Set Rec = Db.OpenRecordSet("Mailing List")
- In your TextBox Click() event, type the following:
Rec.AddNew
Rec("Mailing List") = "" ' You set the contents of the record as you like any time anywhere in the program.
Rec.Update
- Don't forget before your terminate your program, you have to type the following where feel it's appropriate:
Db.Close
Hope this helps,
Wesam
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.