SQL "Insert Into" question

J

johnb

I have the following SQL as part of a VBA Sub
strSql = "INSERT INTO [tbl_Parts] ( CPS_ID, FramePart, Mullpart, TransPart)
" & _
"SELECT " & lngID & " As CPS_ID, FramePart, Mullpart, TransPart " & _
"FROM [tbl_parts] WHERE CPS_ID = " & Me.CPS_ID & ";"
And it works great!

The "CPS_ID, FramePart, Mullpart, TransPart" part are only 4 fields but the
rest of the Form has another 50 or so fields. Do I have to type All the
fileds or is there another method of populating the 50 or so fields??

TIA
johnb
 
A

Alex Dybenko

Hi,
you can either go through all form's controls:

for each ctl in me.control

next ctl

check if control is textbox or combobox, and then build your sql based on
control names

OR
go through fields of tbl_parts table and get field names there

for each fld in tdf.fields


--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
J

johnb

Cheers Alex

Just what I wanted!

regards
johnb

Alex Dybenko said:
Hi,
you can either go through all form's controls:

for each ctl in me.control

next ctl

check if control is textbox or combobox, and then build your sql based on
control names

OR
go through fields of tbl_parts table and get field names there

for each fld in tdf.fields


--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


johnb said:
I have the following SQL as part of a VBA Sub
strSql = "INSERT INTO [tbl_Parts] ( CPS_ID, FramePart, Mullpart,
TransPart)
" & _
"SELECT " & lngID & " As CPS_ID, FramePart, Mullpart, TransPart " & _
"FROM [tbl_parts] WHERE CPS_ID = " & Me.CPS_ID & ";"
And it works great!

The "CPS_ID, FramePart, Mullpart, TransPart" part are only 4 fields but
the
rest of the Form has another 50 or so fields. Do I have to type All the
fileds or is there another method of populating the 50 or so fields??

TIA
johnb
 

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