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
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
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".
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.