PC Review


Reply
Thread Tools Rate Thread

SQL question on "Insert into "

 
 
=?Utf-8?B?am9obmI=?=
Guest
Posts: n/a
 
      21st Feb 2007
I'm trying to loop thru all non PK or FK controls on a Form/Subform using the
sql statement below, but I get an error message "Number of query values and
destination field do not match".

I'd be grateful if some kind person point out the error of my ways!

TIA johnb

If Me.[SubForm1].Form.RecordsetClone.RecordCount > 0 Then
For Each ctl In Me.Controls

If ctl.Name = "Parts_ID" Or ctl.Name = "CPD_ID" Or ctl.ControlType =
acLabel Then
GoTo Flag1
End If

strSql = "INSERT INTO [tbl_Parts]( " & ctl.Name & ") " & _
"SELECT " & lngID & " As CPS_ID, " & ctl.Name & _
" FROM [tbl_parts] WHERE CPS_ID = " & Me.CPS_ID & ";"
Debug.Print strSql
DBEngine(0)(0).Execute strSql, dbFailOnError
Flag1:
Next ctl
Else
MsgBox "Main record duplicated, but there were no related
records."
End If

 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      21st Feb 2007
hi John,

johnb wrote:
> GoTo Flag1

Shame upon you for using GoTo.

If Me.[SubForm1].Form.RecordsetClone.RecordCount > 0 Then

For Each ctl In Me.Controls
If Not (ctl.Name = "Parts_ID" Or _
ctl.Name = "CPD_ID" Or _
ctl.ControlType = acLabel) Then
strSql = "INSERT INTO [tbl_Parts]( " & ctl.Name & ") " & _
"SELECT " & lngID & " As CPS_ID, " & ctl.Name & _
" FROM [tbl_parts] WHERE CPS_ID = " & Me.CPS_ID & ";"
Debug.Print strSql
DBEngine(0)(0).Execute strSql, dbFailOnError
End If
Next ctl

Else
MsgBox "Main record duplicated, " & _
"but there were no related records."
End If


The number of fields to insert

INSERT INTO Table(fields)

must match the number of fields in your select

SELECT fields

..

Your insert field list consists of one field, but your select has two
fields.

mfG
--> stefan <--

 
Reply With Quote
 
=?Utf-8?B?am9obmI=?=
Guest
Posts: n/a
 
      22nd Feb 2007
Cheers Stefan

"Stefan Hoffmann" wrote:

> hi John,
>
> johnb wrote:
> > GoTo Flag1

> Shame upon you for using GoTo.
>
> If Me.[SubForm1].Form.RecordsetClone.RecordCount > 0 Then
>
> For Each ctl In Me.Controls
> If Not (ctl.Name = "Parts_ID" Or _
> ctl.Name = "CPD_ID" Or _
> ctl.ControlType = acLabel) Then
> strSql = "INSERT INTO [tbl_Parts]( " & ctl.Name & ") " & _
> "SELECT " & lngID & " As CPS_ID, " & ctl.Name & _
> " FROM [tbl_parts] WHERE CPS_ID = " & Me.CPS_ID & ";"
> Debug.Print strSql
> DBEngine(0)(0).Execute strSql, dbFailOnError
> End If
> Next ctl
>
> Else
> MsgBox "Main record duplicated, " & _
> "but there were no related records."
> End If
>
>
> The number of fields to insert
>
> INSERT INTO Table(fields)
>
> must match the number of fields in your select
>
> SELECT fields
>
> ..
>
> Your insert field list consists of one field, but your select has two
> fields.
>
> mfG
> --> stefan <--
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I save "details" View + "Date Modified" in "insert file" Kevin Clough Microsoft Outlook Discussion 1 16th Jun 2008 11:59 PM
The "Symbol" under "Insert" disappeared and replaced by "Number" =?Utf-8?B?RWxpbmc=?= Microsoft Word Document Management 3 13th Sep 2006 04:29 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Microsoft Excel Misc 3 26th Oct 2005 12:36 AM
MS Outlook 2003 "insert" vs "attach" question =?Utf-8?B?bG9yZW4=?= Microsoft Outlook Discussion 1 16th Feb 2005 04:57 PM
File: "Insert as Shortcut" replaced by "Insert as Hyperlink" Paul Martin Microsoft Outlook Discussion 3 23rd Feb 2004 01:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:27 AM.