INSERT statement

astarbyfar

Registered User.
Local time
Today, 15:36
Joined
Apr 27, 2003
Messages
93
Ive got the following INSERT statement

Dim SQL As String
Private Sub Save_Click()

[Forms]![Entry settings]![PSM Code] = [Forms]![New Part settings]![PSMCode]

[Forms]![Entry settings]![PSM Code].SetFocus

SQL = "INSERT INTO Part(PSM Code, Part Prefix, Part Base, Part Suffix, Part Description, Batch Number, Base No, Model, Model No, Die Bay, Pallet No, Pallet Spec)" &

"VALUES ('" & [PSM Code].Value & "', '" & [Part Prefix].Value & "', '" & [Part Base].Value & "', '" & [Part Suffix].Value & "', '" & [Part Description].Value & "', '" & [Batch Number].Value & "', '" & [Base No].Value & "', '" & [Model].Value & "', '" & [Model No].Value & "', '" & [Die Bay].Value & "', '" & [Pallet No].Value & "', '" & [Pallet Spec].Value & "')"""

DoCmd.RunSQL "SQL"
DoCmd.RunMacro "Close"

End Sub


By the way the attribute Base No (which is highlighted and where the rror is created!) is made up of the concatenation of Part Prefix, Part Base and Part Suffix. In the text box Base No I have the control source as:

=[Part Prefix]& "" &[Part Base]& "" &[Part Suffix]

Hence the text box Base No should hold the value created by the above command.

It may seem odd to record a value obtained from another three but we need to store this intial value as an identifier for an entity which will be used later.

Has anyone any idea what is up here?
 
Hi astarbyfar,
Did you notice you didn't mention what problem you were having? Let me take a guess. My preference would be:
CurrentDB.Execute SQL, dbFailOnError
...but you could probably fix your problem by removing the quotes around "SQL":
DoCmd.RunSQL SQL
 

Users who are viewing this thread

Back
Top Bottom