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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank Records

Status
Not open for further replies.

Leeus

Programmer
Sep 10, 2001
40
GB
I'm trying to create a form that will create a number of blank records in a table, dependent on the number on the text box, I'm having alot of trouble with this one!
 
Why not use the value in the text box as an index in a loop that creates the blank records? Let's say that the name of the text box containing the number is LoopTimes. I'm assuming that you press a button to add the blank records. If so, put this code in the OnClick event.

Set Db = CurrentDb
Set recset = Db.OpenRecordset("table name", dbOpenDynaset)
Dim numRecs as integer

numRecs = LoopTimes.Value

For i = 1 to numRecs
recset.AddNew
recset.Update
Next i

 
I forgot to include some Dim statements. This should be complete.

Dim Db as DAO.Database
Dim recset as DAO.Recordset
Dim numRecs as Integer
Dim i as Integer

Set Db = CurrentDb
Set recset = Db.OpenRecordset("table name", dbOpenDynaset)

numRecs = LoopTimes.Value

For i = 1 to numRecs
recset.AddNew
recset.Update
Next i

By the way, I tested this code and it works.

dz
 
Sorry I get an error on this line,
Dim Db As DAO.Database

??

Cheers,
Leeus
 
Hi Leeus,

What version of Access are you using? I believe that Access 97 defaults to DAO without specifying it. I am using Access 2000. If you are using Access 97, just omit DAO. It should still work. When you type "Dim Db as d" in the VB editor, does DAO show as an option? If not, your version must not support it. Try this:

Dim Db as Database
Dim recset as Recordset
Dim numRecs as Integer
Dim i as Integer

Set Db = CurrentDb
Set recset = Db.OpenRecordset("table name", dbOpenDynaset)

numRecs = LoopTimes.Value

For i = 1 to numRecs
recset.AddNew
recset.Update
Next i

dz
 
I just checked a computer that has Access 97 and it has the DAO option. Are you sure that you didn't type it wrong? When typing in VB, it will prompt you for valid code. If you type "Dim db as d", the editor will display all valid options that start with the letter "D".

dz
 
If you are using verson 2k it may be the DAO 3.6 library is not referenced. Go to Tools, references (from the code window) and make sure Microsoft DAO 3.6 Object library has a tick by it. Fox's code should then work.

HTH

Nigel
 
Cheers, the referncing worked, is there an FAQ somewhere with tips about references etc.???

Cheers any way guys worked a treat.
 
Ummmmm....

As a principle of database design, never add blank records....sounds like you've got a design problem somewhere.....

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top