Form - table entries

J

Jim Kennedy

Hi,
Here's how I tackled this. I created an unbound form and
added 3 text boxes (text1,2, & 3) to hold the data I want
and then a 4th text box (repeat) to enter the number of
records I want to add. Then I added a command button and
entered this code:

Private Sub cmdAdd_Click()
Dim i As Integer
Dim intCount
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "games", CurrentProject.Connection, _
adOpenStatic, adLockOptimistic, adCmdTable

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"

rs.close
set rs = nothing

End Sub

You'll have to customize it for your table and field
names, but maybe this will get you started in the right
direction.

Jim
 
M

Maggie

Hi,

Yes can you please give an example, I dont really
understand what you were talking about in your first
paragraph - I dont see where your telling me to look,
thanks.

Maggie
-----Original Message-----
You don't have the ADO library referenced. I think you
can turn it on by going to your tools, references from
within a module. Now find Microsoft Activex DataObjects
Library Version (whatever is the highest number).

If that doesn't work you will have to change the code to
DAO. You can find an example in help, or I can send an
example if needed.

Jim
-----Original Message-----
Hello,

You have a good idea, and i followed your lead, however,
the line

Dim rs As ADODB.Recordset

causes an error (Userdefined type not defined)

any help with this? (i have access 97) Thanks

Maggie
-----Original Message-----
Hi,
Here's how I tackled this. I created an unbound form and
added 3 text boxes (text1,2, & 3) to hold the data I want
and then a 4th text box (repeat) to enter the number of
records I want to add. Then I added a command button and
entered this code:

Private Sub cmdAdd_Click()
Dim i As Integer
Dim intCount
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "games", CurrentProject.Connection, _
adOpenStatic, adLockOptimistic, adCmdTable

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"

rs.close
set rs = nothing

End Sub

You'll have to customize it for your table and field
names, but maybe this will get you started in the right
direction.

Jim
-----Original Message-----
Hello,

This may be an easy question, (or maybe not), essentially
I will constantly add to a table that has about 8 fields
in large numbers. For instance, I will add 100-200
records where 4/8 fields will be the same. I would like
to make a form that shows all the fields with textboxes,
I fill in the common data, then enter a number of records
I want, and then press a command button to create the
fields.

For example, I would have a 100 records with the same
name as the first field. I would like to enter the name,
then enter 100 and it will create 100 new entries in the
table with that name in every record. I am new to
access, any help would greatly be appreciated!

Thanks,

Maggie
.

.
.
.
 
J

Jim Kennedy

Ok, here's the same example using DAO.

Private Sub cmdAdd_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim intCount

Set db = CurrentDb()
Set rs = db.OpenRecordset("games")

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"



rs.Close
db.Close
End Sub

-----Original Message-----
Hi,

Yes can you please give an example, I dont really
understand what you were talking about in your first
paragraph - I dont see where your telling me to look,
thanks.

Maggie
-----Original Message-----
You don't have the ADO library referenced. I think you
can turn it on by going to your tools, references from
within a module. Now find Microsoft Activex DataObjects
Library Version (whatever is the highest number).

If that doesn't work you will have to change the code to
DAO. You can find an example in help, or I can send an
example if needed.

Jim
-----Original Message-----
Hello,

You have a good idea, and i followed your lead, however,
the line

Dim rs As ADODB.Recordset

causes an error (Userdefined type not defined)

any help with this? (i have access 97) Thanks

Maggie

-----Original Message-----
Hi,
Here's how I tackled this. I created an unbound form
and
added 3 text boxes (text1,2, & 3) to hold the data I
want
and then a 4th text box (repeat) to enter the number of
records I want to add. Then I added a command button
and
entered this code:

Private Sub cmdAdd_Click()
Dim i As Integer
Dim intCount
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "games", CurrentProject.Connection, _
adOpenStatic, adLockOptimistic, adCmdTable

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"

rs.close
set rs = nothing

End Sub

You'll have to customize it for your table and field
names, but maybe this will get you started in the right
direction.

Jim
-----Original Message-----
Hello,

This may be an easy question, (or maybe not),
essentially
I will constantly add to a table that has about 8
fields
in large numbers. For instance, I will add 100-200
records where 4/8 fields will be the same. I would
like
to make a form that shows all the fields with
textboxes,
I fill in the common data, then enter a number of
records
I want, and then press a command button to create the
fields.

For example, I would have a 100 records with the same
name as the first field. I would like to enter the
name,
then enter 100 and it will create 100 new entries in
the
table with that name in every record. I am new to
access, any help would greatly be appreciated!

Thanks,

Maggie
.

.

.
.
.
 
M

Maggie

I dont know how it works, but it works and I thank you
for that!

maggie
-----Original Message-----
Ok, here's the same example using DAO.

Private Sub cmdAdd_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim intCount

Set db = CurrentDb()
Set rs = db.OpenRecordset("games")

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"



rs.Close
db.Close
End Sub

-----Original Message-----
Hi,

Yes can you please give an example, I dont really
understand what you were talking about in your first
paragraph - I dont see where your telling me to look,
thanks.

Maggie
-----Original Message-----
You don't have the ADO library referenced. I think you
can turn it on by going to your tools, references from
within a module. Now find Microsoft Activex DataObjects
Library Version (whatever is the highest number).

If that doesn't work you will have to change the code to
DAO. You can find an example in help, or I can send an
example if needed.

Jim
-----Original Message-----
Hello,

You have a good idea, and i followed your lead, however,
the line

Dim rs As ADODB.Recordset

causes an error (Userdefined type not defined)

any help with this? (i have access 97) Thanks

Maggie

-----Original Message-----
Hi,
Here's how I tackled this. I created an unbound form
and
added 3 text boxes (text1,2, & 3) to hold the data I
want
and then a 4th text box (repeat) to enter the number of
records I want to add. Then I added a command button
and
entered this code:

Private Sub cmdAdd_Click()
Dim i As Integer
Dim intCount
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "games", CurrentProject.Connection, _
adOpenStatic, adLockOptimistic, adCmdTable

intCount = Me.Repeat

For i = 1 To intCount
rs.AddNew
rs![game_no] = Me.Text1
rs![winner] = Me.Text2
rs![loser] = Me.Text3
rs.Update
Next i

MsgBox "done"

rs.close
set rs = nothing

End Sub

You'll have to customize it for your table and field
names, but maybe this will get you started in the right
direction.

Jim
-----Original Message-----
Hello,

This may be an easy question, (or maybe not),
essentially
I will constantly add to a table that has about 8
fields
in large numbers. For instance, I will add 100-200
records where 4/8 fields will be the same. I would
like
to make a form that shows all the fields with
textboxes,
I fill in the common data, then enter a number of
records
I want, and then press a command button to create the
fields.

For example, I would have a 100 records with the same
name as the first field. I would like to enter the
name,
then enter 100 and it will create 100 new entries in
the
table with that name in every record. I am new to
access, any help would greatly be appreciated!

Thanks,

Maggie
.

.

.

.
.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top