Insert records

G

GGill

I have table 'tblData' with field name 'Name1', 'Name2', 'Name3' and
'CopyofNumber'. If in my form i entered for this fields 'Name1'=A, 'Name2'=B,
'Name3'=C and i entered for example for field 'CopyofNumber' = 5 then when i
click on button 'Create'. I will need to inseret to the table 5 records (base
on field 'CopyofNumber'). So it should look like this in a table 'tblData':
'Name1' 'Name2' 'Name3'
A B C
A B C
A B C
A B C
A B C

Please help me!!!!!!!!
 
D

Douglas J Steele

That's an unusual request: it's not usually recommended to create "place
holder" records like that.

In any case, you could use code like the following to accomplish this:

Private Sub btnCreate_Click()

Dim intLoop As Integer
Dim strSQL As String

strSQL = "INSERT INTO tblData (Name1, Name2, Name3) " & _
"VALUES (" & Chr$(34) & Me.txtName1 & Chr$(34) & ", " & _
Chr$(34) & Me.txtName2 & Chr$(34) & ", " & _
Chr$(34) & Me.txtName3 & Chr$(34) & ")"

For intLoop = 1 to Me.txtCopies
CurrentDb.Execute strSQL, dbFailOnError
Next intLoop

End Sub


Note that I haven't included any error checking in the above.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


GGill said:
I have table 'tblData' with field name 'Name1', 'Name2', 'Name3' and
'CopyofNumber'. If in my form i entered for this fields 'Name1'=A, 'Name2'=B,
'Name3'=C and i entered for example for field 'CopyofNumber' = 5 then when i
click on button 'Create'. I will need to inseret to the table 5 records (base
 
G

GGill

Hello,
I did use this code, some how i am receiving error message "Run-Time error
3464. Data type mismatch in criteria expression."
Please let me know what i need to do to make this code work.

Thank you.

Douglas J Steele said:
That's an unusual request: it's not usually recommended to create "place
holder" records like that.

In any case, you could use code like the following to accomplish this:

Private Sub btnCreate_Click()

Dim intLoop As Integer
Dim strSQL As String

strSQL = "INSERT INTO tblData (Name1, Name2, Name3) " & _
"VALUES (" & Chr$(34) & Me.txtName1 & Chr$(34) & ", " & _
Chr$(34) & Me.txtName2 & Chr$(34) & ", " & _
Chr$(34) & Me.txtName3 & Chr$(34) & ")"

For intLoop = 1 to Me.txtCopies
CurrentDb.Execute strSQL, dbFailOnError
Next intLoop

End Sub


Note that I haven't included any error checking in the above.
 
D

Douglas J. Steele

What's the exact code you're trying to run?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


GGill said:
Hello,
I did use this code, some how i am receiving error message "Run-Time error
3464. Data type mismatch in criteria expression."
Please let me know what i need to do to make this code work.

Thank you.
 
G

GGill

Doug Thank you so much your code is working now. I just fixed design of my
table.

Thank you again.
 

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