Error: Run-time error '3061'. Too few parameters. Expected 1 - vba

FSQL = "INSERT INTO Q_ClientSearch(SName, OName, Add1, Add2, Add3, TelNo, Email, NID) " & _
" VALUES('" & M_SName & "', '" & M_OName & "', '" & M_Add1 & "', '" & M_Add2 & _
"', '" & M_Add3 & "', '" & M_Phone & "', '" & M_Email & "', '" & M_IDNo & "') "
DoCmd.RunSQL FSQL
Note: All the fields in table are string variable

String concatenation will only give you troubles and is difficult to maintain. Please use parameters.
Create a query, copy the SQL below and the call it from VBA.
The query:
PARAMETERS [prmSName] Text(255), [prmOName] Text (255), [prmAdd1] Text(255), [prmAdd2] Text(255),
[prmAdd3] Text(255), [prmTelNo] Text(255), [prmEmail] Text(255), [prmNID] Text(255);
INSERT INTO Q_ClientSearch(SName, OName, Add1, Add2, Add3, TelNo, Email, NID)
SELECT [prmSName] AS SName, [prmOName] AS OName, [prmAdd1] AS SName, [prmSName] AS Add1,
[prmAdd2] AS Add2, [prmAdd3] AS Add3, [prmEmail] AS Email, [prmNID] AS NID;
To call it:
With CurrentDb().QueryDefs("YourQueryName")
.Parameters("[prmSName]").Value = M_SName
.Parameters("[prmOName]").Value = M_OName
.Parameters("[prmAdd1]").Value = M_Add1
.Parameters("[prmAdd2]").Value = M_Add2
.Parameters("[prmAdd3]").Value = M_Add3
.Parameters("[prmTelNo]").Value = M_Phone
.Parameters("[prmEmail]").Value = M_Email
.Parameters("[prmNID]").Value = M_IDNo
.Execute dbFailOnError
End With

Related

Run time error 3061 Too few parameters expected 4

CurrentDb.Execute "UPDATE Customer set [FirstName] = " & Me.FirstName & _
" ,[LastName] = " & Me.LastName & _
" ,[PhoneNumber] = '" & Me.PhoneNumber & _
"' ,[Address] = '" & Me.Address & _
"' ,[City] = " & Me.City & _
" ,[State] = " & Me.State & _
" ,[ZipCode] = " & Me.ZipCode & " WHERE ([E-mail] = '" & Me.email & "')"
what is wrong with this update query. Please help.
Once again, consider SQL parameterization, an industry best practice when working with SQL, which is supported in MS Access using PARAMETERS clause and QueryDefs. You avoid messy concatenation, quote enclosures (which you are missing quite a bit for your text fields), and possibly SQL injection as such fields are open to users.
SQL (save as a stored Access query)
PARAMETERS [FirstNameParam] Text(255), [LastNameParam] Text(255),
[PhoneNumberParam] Text(255), [AddressParam] Text(255),
[CityParam] Text(255), [StateParam] Text(255),
[ZipCodeParam] Text(255), [EmailParam] Text(255);
UPDATE Customer
SET [FirstName] = [FirstNameParam],
[LastName] = [LastNameParam],
[PhoneNumber] = [PhoneNumberParam],
[Address] = [AddressParam],
[City] = [CityParam],
[State] = [StateParam],
[ZipCode] = [ZipCodeParam]
WHERE ([E-mail] = [EmailParam]);
VBA
Dim qdef As QueryDef
Set qdef = CurrentDb.QueryDefs("mySavedParameterQuery")
' BIND VALUES TO PARAMETER PLACEHOLDERS
qdef![FirstNameParam] = Me.FirstName
qdef![LastNameParam] = Me.LastName
qdef![PhoneNumberParam] = Me.PhoneNumber
qdef![AddressParam] = Me.Address
qdef![CityParam] = Me.City
qdef![StateParam] = Me.State
qdef![ZipCodeParam] = Me.ZipCode
qdef![EmailParam] = Me.Email
' EXECUTE ACTION QUERY
qdef.Execute dbFailOnError
Set qdef = Nothing
Just a guess from looking at your SQL and the error - I suspect your 4 field names with two words should likely have spaces between the two words: [FirstName] becomes [First Name], [Last Name] becomes [Last Name] and so on
So SQL string should actually be
"UPDATE Customer set [First Name] = " & Me.FirstName & _
" ,[Last Name] = " & Me.LastName & _
" ,[Phone Number] = '" & Me.PhoneNumber & _
"' ,[Address] = '" & Me.Address & _
"' ,[City] = " & Me.City & _
" ,[State] = " & Me.State & _
" ,[Zip Code] = " & Me.ZipCode & " WHERE ([E-mail] = '" & Me.email & "')"
As #Jiggles32 says - the only way to know for sure is to show us your field names from the Customer table

currentdb.execute insert into syntax issues [duplicate]

This question already has an answer here:
Why is there a VBA syntax error in this multi-line of code?
(1 answer)
Closed 5 years ago.
I am trying to assign this code to a button on an access form in order to enter data from the form to the assigned table (Results), clear the form then focus back on the top of the form. It seems I am having syntax issues with the currentdb.execute part of the code.
Private Sub Command510_Click()
CurrentDb.Execute "INSERT INTO Results ([QC specialist],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31] _
,[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60],[61],[62],[63],[64],[65],[66],[67],[68],[Comment (1)] _
,[Comment (2)],[Comment (3)],[Comment (4)],[Comment (5)],[Comment (6)],[Comment (7)],[Comment (8)],[Comment (9)],[Comment (10)],[Comment (11)],[Comment (12)],[Comment (13)],[Comment (14)],[Comment (15)] _
,[Comment (16)],[Comment (17)],[Comment (18)],[Comment (19)],[Comment (20)],[Comment (21)],[Comment (22)],[Comment (23)],[Comment (24)],[Comment (25)],[Comment (26)],[Comment (27)],[Comment (28)] _
,[Comment (29)],[Comment (30)],[Comment (31)],[Comment (32)],[Comment (33)],[Comment (34)],[Comment (35)],[Comment (36)],[Comment (37)],[Comment (38)],[Comment (39)],[Comment (40)],[Comment (41)] _
,[Comment (42)],[Comment (43)],[Comment (44)],[Comment (45)],[Comment (46)],[Comment (47)],[Comment (48)],[Comment (49)],[Comment (50)],[Comment (51)],[Comment (52)],[Comment (53)],[Comment (54)] _
,[Comment (55)],[Comment (56)],[Comment (57)],[Comment (58)],[Comment (59)],[Comment (60)],[Comment (61)],[Comment (62)],[Comment (63)],[Comment (64)],[Comment (65)],[Comment (66)],[Comment (67)],[Comment (68)],[Loan Number],[Submission Date])" _
& "VALUES ('" & Me.[Combo147] & "','" & Me.[Combo165] & "','" & Me.[Combo170] & "','" & Me.[Combo172] & "','" & Me.[Combo174] & "','" & Me.[Combo176] & "','" & Me.[Combo178] & "','" & _
Me.[Combo214] & "','" & Me.[Combo216] & "','" & Me.[Combo218] & "','" & Me.[Combo220] & "','" & Me.[Combo222] & "','" & Me.[Combo224] & "','" & Me.[Combo226] & "','" & Me.[Combo228] & "','" & _
Me.[Combo230] & "','" & Me.[Combo232] & "','" & Me.[Combo237] & "','" & Me.[Combo239] & "','" & Me.[Combo241] & "','" & Me.[Combo243] & "','" & Me.[Combo245] & "','" & Me.[Combo247] & "','" & _
Me.[Combo249] & "','" & Me.[Combo251] & "','" & Me.[Combo253] & "','" & Me.[Combo255] & "','" & Me.[Combo257] & "','" & Me.[Combo259] & "','" & Me.[Combo261] & "','" & Me.[Combo263] & "','" & _
Me.[Combo265] & "','" & Me.[Combo267] & "','" & Me.[Combo269] & "','" & Me.[Combo271] & "','" & Me.[Combo273] & "','" & Me.[Combo275] & "','" & Me.[Combo277] & "','" & Me.[Combo279] & "','" & _
Me.[Combo281] & "','" & Me.[Combo283] & "','" & Me.[Combo285] & "','" & Me.[Combo287] & "','" & Me.[Combo289] & "','" & Me.[Combo291] & "','" & Me.[Combo293] & "','" & Me.[Combo295] & "','" & _
Me.[Combo297] & "','" & Me.[Combo299] & "','" & Me.[Combo301] & "','" & Me.[Combo303] & "','" & Me.[Combo305] & "','" & Me.[Combo307] & "','" & Me.[Combo309] & "','" & Me.[Combo311] & "','" & _
Me.[Combo313] & "','" & Me.[Combo315] & "','" & Me.[Combo317] & "','" & Me.[Combo319] & "','" & Me.[Combo321] & "','" & Me.[Combo323] & "','" & Me.[Combo325] & "','" & Me.[Combo327] & "','" & _
Me.[Combo333] & "','" & Me.[Combo335] & "','" & Me.[Combo337] & "','" & Me.[Combo339] & "','" & Me.[Combo341] & "','" & Me.[Combo343] & "','" & Me.[Text347] & "','" & Me.[Text349] & "','" & _
Me.[Text351] & "','" & Me.[Text353] & "','" & Me.[Text355] & "','" & Me.[Text357] & "','" & Me.[Text359] & "','" & Me.[Text361] & "','" & Me.[Text363] & "','" & Me.[Text365] & "','" & _
Me.[Text367] & "','" & Me.[Text371] & "','" & Me.[Text373] & "','" & Me.[Text375] & "','" & Me.[Text377] & "','" & Me.[Text379] & "','" & Me.[Text395] & "','" & Me.[Text397] & "','" & _
Me.[Text399] & "','" & Me.[Text401] & "','" & Me.[Text403] & "','" & Me.[Text405] & "','" & Me.[Text407] & "','" & Me.[Text409] & "','" & Me.[Text411] & "','" & Me.[Text413] & "','" & _
Me.[Text415] & "','" & Me.[Text417] & "','" & Me.[Text419] & "','" & Me.[Text421] & "','" & Me.[Text423] & "','" & Me.[Text425] & "','" & Me.[Text427] & "','" & Me.[Text429] & "','" & _
Me.[Text431] & "','" & Me.[Text433] & "','" & Me.[Text437] & "','" & Me.[Text439] & "','" & Me.[Text441] & "','" & Me.[Text443] & "','" & Me.[Text445] & "','" & Me.[Text447] & "','" & _
Me.[Text449] & "','" & Me.[Text451] & "','" & Me.[Text453] & "','" & Me.[Text455] & "','" & Me.[Text457] & "','" & Me.[Text459] & "','" & Me.[Text461] & "','" & Me.[Text463] & "','" & _
Me.[Text465] & "','" & Me.[Text467] & "','" & Me.[Text469] & "','" & Me.[Text471] & "','" & Me.[Text473] & "','" & Me.[Text475] & "','" & Me.[Text477] & "','" & Me.[Text479] & "','" & _
Me.[Text481] & "','" & Me.[Text483] & "','" & Me.[Text485] & "','" & Me.[Text487] & "','" & Me.[Text489] & "','" & Me.[Text491] & "','" & Me.[Text493] & "','" & Me.[Text495] & "','" & _
Me.[Text497] & "','" & Me.[Text501] & "','" & Me.[Text504] & "','" & Me.[Text163] & "')"
'clear fields
cmdClear_Click
'focus on top
Me.Combo147.SetFocus
End Sub
Thank you in advance !
Consider querydef parameterization. This is a quintessential need that parameterization is not all about sql injection but properly abstracting SQL code from data interpolation.
Save your parameterized, prepared SQL statement (no data) as an MS Access query object avoiding any need of double quotes or string concatenation. Then in VBA, reference this saved query, bind actual values from form controls to parameter placeholders, then execute the query.
SQL (save once as a stored query object; all columns assumed short text type)
PARAMETERS [Combo147Param] TEXT(255), [Combo165Param] TEXT(255), [Combo170Param] TEXT(255), [Combo172Param] TEXT(255), [Combo174Param] TEXT(255), [Combo176Param] TEXT(255), [Combo178Param] TEXT(255),
[Combo214Param] TEXT(255), [Combo216Param] TEXT(255), [Combo218Param] TEXT(255), [Combo220Param] TEXT(255), [Combo222Param] TEXT(255), [Combo224Param] TEXT(255), [Combo226Param] TEXT(255), [Combo228Param] TEXT(255),
[Combo230Param] TEXT(255), [Combo232Param] TEXT(255), [Combo237Param] TEXT(255), [Combo239Param] TEXT(255), [Combo241Param] TEXT(255), [Combo243Param] TEXT(255), [Combo245Param] TEXT(255), [Combo247Param] TEXT(255),
[Combo249Param] TEXT(255), [Combo251Param] TEXT(255), [Combo253Param] TEXT(255), [Combo255Param] TEXT(255), [Combo257Param] TEXT(255), [Combo259Param] TEXT(255), [Combo261Param] TEXT(255), [Combo263Param] TEXT(255),
[Combo265Param] TEXT(255), [Combo267Param] TEXT(255), [Combo269Param] TEXT(255), [Combo271Param] TEXT(255), [Combo273Param] TEXT(255), [Combo275Param] TEXT(255), [Combo277Param] TEXT(255), [Combo279Param] TEXT(255),
[Combo281Param] TEXT(255), [Combo283Param] TEXT(255), [Combo285Param] TEXT(255), [Combo287Param] TEXT(255), [Combo289Param] TEXT(255), [Combo291Param] TEXT(255), [Combo293Param] TEXT(255), [Combo295Param] TEXT(255),
[Combo297Param] TEXT(255), [Combo299Param] TEXT(255), [Combo301Param] TEXT(255), [Combo303Param] TEXT(255), [Combo305Param] TEXT(255), [Combo307Param] TEXT(255), [Combo309Param] TEXT(255), [Combo311Param] TEXT(255),
[Combo313Param] TEXT(255), [Combo315Param] TEXT(255), [Combo317Param] TEXT(255), [Combo319Param] TEXT(255), [Combo321Param] TEXT(255), [Combo323Param] TEXT(255), [Combo325Param] TEXT(255), [Combo327Param] TEXT(255),
[Combo333Param] TEXT(255), [Combo335Param] TEXT(255), [Combo337Param] TEXT(255), [Combo339Param] TEXT(255), [Combo341Param] TEXT(255), [Combo343Param] TEXT(255), [Text347Param] TEXT(255), [Text349Param] TEXT(255),
[Text351Param] TEXT(255), [Text353Param] TEXT(255), [Text355Param] TEXT(255), [Text357Param] TEXT(255), [Text359Param] TEXT(255), [Text361Param] TEXT(255), [Text363Param] TEXT(255), [Text365Param] TEXT(255),
[Text367Param] TEXT(255), [Text371Param] TEXT(255), [Text373Param] TEXT(255), [Text375Param] TEXT(255), [Text377Param] TEXT(255), [Text379Param] TEXT(255), [Text395Param] TEXT(255), [Text397Param] TEXT(255),
[Text399Param] TEXT(255), [Text401Param] TEXT(255), [Text403Param] TEXT(255), [Text405Param] TEXT(255), [Text407Param] TEXT(255), [Text409Param] TEXT(255), [Text411Param] TEXT(255), [Text413Param] TEXT(255),
[Text415Param] TEXT(255), [Text417Param] TEXT(255), [Text419Param] TEXT(255), [Text421Param] TEXT(255), [Text423Param] TEXT(255), [Text425Param] TEXT(255), [Text427Param] TEXT(255), [Text429Param] TEXT(255),
[Text431Param] TEXT(255), [Text433Param] TEXT(255), [Text437Param] TEXT(255), [Text439Param] TEXT(255), [Text441Param] TEXT(255), [Text443Param] TEXT(255), [Text445Param] TEXT(255), [Text447Param] TEXT(255),
[Text449Param] TEXT(255), [Text451Param] TEXT(255), [Text453Param] TEXT(255), [Text455Param] TEXT(255), [Text457Param] TEXT(255), [Text459Param] TEXT(255), [Text461Param] TEXT(255), [Text463Param] TEXT(255),
[Text465Param] TEXT(255), [Text467Param] TEXT(255), [Text469Param] TEXT(255), [Text471Param] TEXT(255), [Text473Param] TEXT(255), [Text475Param] TEXT(255), [Text477Param] TEXT(255), [Text479Param] TEXT(255),
[Text481Param] TEXT(255), [Text483Param] TEXT(255), [Text485Param] TEXT(255), [Text487Param] TEXT(255), [Text489Param] TEXT(255), [Text491Param] TEXT(255), [Text493Param] TEXT(255), [Text495Param];
INSERT INTO Results ([QC specialist],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31]
,[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60],[61],[62],[63],[64],[65],[66],[67],[68],[Comment (1)]
,[Comment (2)],[Comment (3)],[Comment (4)],[Comment (5)],[Comment (6)],[Comment (7)],[Comment (8)],[Comment (9)],[Comment (10)],[Comment (11)],[Comment (12)],[Comment (13)],[Comment (14)],[Comment (15)]
,[Comment (16)],[Comment (17)],[Comment (18)],[Comment (19)],[Comment (20)],[Comment (21)],[Comment (22)],[Comment (23)],[Comment (24)],[Comment (25)],[Comment (26)],[Comment (27)],[Comment (28)]
,[Comment (29)],[Comment (30)],[Comment (31)],[Comment (32)],[Comment (33)],[Comment (34)],[Comment (35)],[Comment (36)],[Comment (37)],[Comment (38)],[Comment (39)],[Comment (40)],[Comment (41)]
,[Comment (42)],[Comment (43)],[Comment (44)],[Comment (45)],[Comment (46)],[Comment (47)],[Comment (48)],[Comment (49)],[Comment (50)],[Comment (51)],[Comment (52)],[Comment (53)],[Comment (54)]
,[Comment (55)],[Comment (56)],[Comment (57)],[Comment (58)],[Comment (59)],[Comment (60)],[Comment (61)],[Comment (62)],[Comment (63)],[Comment (64)],[Comment (65)],[Comment (66)],[Comment (67)]
,[Comment (68)],[Loan Number],[Submission Date])
VALUES ([Combo147Param], [Combo165Param], [Combo170Param], [Combo172Param], [Combo174Param], [Combo176Param], [Combo178Param],
[Combo214Param], [Combo216Param], [Combo218Param], [Combo220Param], [Combo222Param], [Combo224Param], [Combo226Param], [Combo228Param],
[Combo230Param], [Combo232Param], [Combo237Param], [Combo239Param], [Combo241Param], [Combo243Param], [Combo245Param], [Combo247Param],
[Combo249Param], [Combo251Param], [Combo253Param], [Combo255Param], [Combo257Param], [Combo259Param], [Combo261Param], [Combo263Param],
[Combo265Param], [Combo267Param], [Combo269Param], [Combo271Param], [Combo273Param], [Combo275Param], [Combo277Param], [Combo279Param],
[Combo281Param], [Combo283Param], [Combo285Param], [Combo287Param], [Combo289Param], [Combo291Param], [Combo293Param], [Combo295Param],
[Combo297Param], [Combo299Param], [Combo301Param], [Combo303Param], [Combo305Param], [Combo307Param], [Combo309Param], [Combo311Param],
[Combo313Param], [Combo315Param], [Combo317Param], [Combo319Param], [Combo321Param], [Combo323Param], [Combo325Param], [Combo327Param],
[Combo333Param], [Combo335Param], [Combo337Param], [Combo339Param], [Combo341Param], [Combo343Param], [Text347Param], [Text349Param],
[Text351Param], [Text353Param], [Text355Param], [Text357Param], [Text359Param], [Text361Param], [Text363Param], [Text365Param],
[Text367Param], [Text371Param], [Text373Param], [Text375Param], [Text377Param], [Text379Param], [Text395Param], [Text397Param],
[Text399Param], [Text401Param], [Text403Param], [Text405Param], [Text407Param], [Text409Param], [Text411Param], [Text413Param],
[Text415Param], [Text417Param], [Text419Param], [Text421Param], [Text423Param], [Text425Param], [Text427Param], [Text429Param],
[Text431Param], [Text433Param], [Text437Param], [Text439Param], [Text441Param], [Text443Param], [Text445Param], [Text447Param],
[Text449Param], [Text451Param], [Text453Param], [Text455Param], [Text457Param], [Text459Param], [Text461Param], [Text463Param],
[Text465Param], [Text467Param], [Text469Param], [Text471Param], [Text473Param], [Text475Param], [Text477Param], [Text479Param],
[Text481Param], [Text483Param], [Text485Param], [Text487Param], [Text489Param], [Text491Param], [Text493Param], [Text495Param])
VBA (call regularly)
Dim qdef As QueryDef
Set qdef = CurrentDb.QueryDefs("myparameterized_savedquery")
qdef![Combo147Param] = Me.[Combo147] : qdef![Combo243Param] = Me.[Combo243]
qdef![Combo165Param] = Me.[Combo165] : qdef![Combo245Param] = Me.[Combo245]
qdef![Combo170Param] = Me.[Combo170] : qdef![Combo247Param] = Me.[Combo247]
qdef![Combo172Param] = Me.[Combo172] : qdef![Combo249Param] = Me.[Combo249]
qdef![Combo174Param] = Me.[Combo174] : qdef![Combo251Param] = Me.[Combo251]
qdef![Combo176Param] = Me.[Combo176] : qdef![Combo253Param] = Me.[Combo253]
qdef![Combo178Param] = Me.[Combo178] : qdef![Combo255Param] = Me.[Combo255]
qdef![Combo214Param] = Me.[Combo214] : qdef![Combo257Param] = Me.[Combo257]
qdef![Combo216Param] = Me.[Combo216] : qdef![Combo259Param] = Me.[Combo259]
qdef![Combo218Param] = Me.[Combo218] : qdef![Combo261Param] = Me.[Combo261]
qdef![Combo220Param] = Me.[Combo220] : qdef![Combo263Param] = Me.[Combo263]
qdef![Combo222Param] = Me.[Combo222] : qdef![Combo265Param] = Me.[Combo265]
qdef![Combo224Param] = Me.[Combo224] : qdef![Combo267Param] = Me.[Combo267]
qdef![Combo226Param] = Me.[Combo226] : qdef![Combo269Param] = Me.[Combo269]
qdef![Combo228Param] = Me.[Combo228] : qdef![Combo271Param] = Me.[Combo271]
qdef![Combo230Param] = Me.[Combo230] : qdef![Combo273Param] = Me.[Combo273]
qdef![Combo232Param] = Me.[Combo232] : qdef![Combo275Param] = Me.[Combo275]
qdef![Combo237Param] = Me.[Combo237] : qdef![Combo277Param] = Me.[Combo277]
qdef![Combo239Param] = Me.[Combo239] : qdef![Combo279Param] = Me.[Combo279]
qdef![Combo241Param] = Me.[Combo241] : qdef![Combo281Param] = Me.[Combo281]
qdef![Combo283Param] = Me.[Combo283] : qdef![Combo323Param] = Me.[Combo323]
qdef![Combo285Param] = Me.[Combo285] : qdef![Combo325Param] = Me.[Combo325]
qdef![Combo287Param] = Me.[Combo287] : qdef![Combo327Param] = Me.[Combo327]
qdef![Combo289Param] = Me.[Combo289] : qdef![Combo333Param] = Me.[Combo333]
qdef![Combo291Param] = Me.[Combo291] : qdef![Combo335Param] = Me.[Combo335]
qdef![Combo293Param] = Me.[Combo293] : qdef![Combo337Param] = Me.[Combo337]
qdef![Combo295Param] = Me.[Combo295] : qdef![Combo339Param] = Me.[Combo339]
qdef![Combo297Param] = Me.[Combo297] : qdef![Combo341Param] = Me.[Combo341]
qdef![Combo299Param] = Me.[Combo299] : qdef![Combo343Param] = Me.[Combo343]
qdef![Combo301Param] = Me.[Combo301] : qdef![Text347Param] = Me.[Text347]
qdef![Combo303Param] = Me.[Combo303] : qdef![Text349Param] = Me.[Text349]
qdef![Combo305Param] = Me.[Combo305] : qdef![Text351Param] = Me.[Text351]
qdef![Combo307Param] = Me.[Combo307] : qdef![Text353Param] = Me.[Text353]
qdef![Combo309Param] = Me.[Combo309] : qdef![Text355Param] = Me.[Text355]
qdef![Combo311Param] = Me.[Combo311] : qdef![Text357Param] = Me.[Text357]
qdef![Combo313Param] = Me.[Combo313] : qdef![Text359Param] = Me.[Text359]
qdef![Combo315Param] = Me.[Combo315] : qdef![Text361Param] = Me.[Text361]
qdef![Combo317Param] = Me.[Combo317] : qdef![Text363Param] = Me.[Text363]
qdef![Combo319Param] = Me.[Combo319] : qdef![Text365Param] = Me.[Text365]
qdef![Combo321Param] = Me.[Combo321] : qdef![Text367Param] = Me.[Text367]
qdef![Text371Param] = Me.[Text371] : qdef![Text425Param] = Me.[Text425]
qdef![Text373Param] = Me.[Text373] : qdef![Text427Param] = Me.[Text427]
qdef![Text375Param] = Me.[Text375] : qdef![Text429Param] = Me.[Text429]
qdef![Text377Param] = Me.[Text377] : qdef![Text431Param] = Me.[Text431]
qdef![Text379Param] = Me.[Text379] : qdef![Text433Param] = Me.[Text433]
qdef![Text395Param] = Me.[Text395] : qdef![Text437Param] = Me.[Text437]
qdef![Text397Param] = Me.[Text397] : qdef![Text439Param] = Me.[Text439]
qdef![Text399Param] = Me.[Text399] : qdef![Text441Param] = Me.[Text441]
qdef![Text401Param] = Me.[Text401] : qdef![Text443Param] = Me.[Text443]
qdef![Text403Param] = Me.[Text403] : qdef![Text445Param] = Me.[Text445]
qdef![Text405Param] = Me.[Text405] : qdef![Text447Param] = Me.[Text447]
qdef![Text407Param] = Me.[Text407] : qdef![Text449Param] = Me.[Text449]
qdef![Text409Param] = Me.[Text409] : qdef![Text451Param] = Me.[Text451]
qdef![Text411Param] = Me.[Text411] : qdef![Text453Param] = Me.[Text453]
qdef![Text413Param] = Me.[Text413] : qdef![Text455Param] = Me.[Text455]
qdef![Text415Param] = Me.[Text415] : qdef![Text457Param] = Me.[Text457]
qdef![Text417Param] = Me.[Text417] : qdef![Text459Param] = Me.[Text459]
qdef![Text419Param] = Me.[Text419] : qdef![Text461Param] = Me.[Text461]
qdef![Text421Param] = Me.[Text421] : qdef![Text463Param] = Me.[Text463]
qdef![Text423Param] = Me.[Text423]
qdef.Execute dbFailOnError
Set qdef = Nothing
And as #Andre comments, please consider a different schema setup to avoid these wide tables. Normalize your database tables for proper one-to-many, many-to-many relationships.
Really should restructure data but in the meantime, concatenate.
CurrentDb.Execute "INSERT INTO Results ([QC specialist],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31]," & _
"[32],[33],[34],[35],[36],[37],[38],[39],[40],[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60],[61],[62],[63],[64],[65],[66],[67],[68],[Comment (1)]," & _
"[Comment (2)],[Comment (3)],[Comment (4)],[Comment (5)],[Comment (6)],[Comment (7)],[Comment (8)],[Comment (9)],[Comment (10)],[Comment (11)],[Comment (12)],[Comment (13)],[Comment (14)],[Comment (15)]," & _
"[Comment (16)],[Comment (17)],[Comment (18)],[Comment (19)],[Comment (20)],[Comment (21)],[Comment (22)],[Comment (23)],[Comment (24)],[Comment (25)],[Comment (26)],[Comment (27)],[Comment (28)]," & _
"[Comment (29)],[Comment (30)],[Comment (31)],[Comment (32)],[Comment (33)],[Comment (34)],[Comment (35)],[Comment (36)],[Comment (37)],[Comment (38)],[Comment (39)],[Comment (40)],[Comment (41)]," & _
"[Comment (42)],[Comment (43)],[Comment (44)],[Comment (45)],[Comment (46)],[Comment (47)],[Comment (48)],[Comment (49)],[Comment (50)],[Comment (51)],[Comment (52)],[Comment (53)],[Comment (54)]," & _
"[Comment (55)],[Comment (56)],[Comment (57)],[Comment (58)],[Comment (59)],[Comment (60)],[Comment (61)],[Comment (62)],[Comment (63)],[Comment (64)],[Comment (65)],[Comment (66)],[Comment (67)],[Comment (68)],[Loan Number],[Submission Date]) " & _

Runtime Error 3134 Microsoft Access

I am having trouble identifying the root cause of my problem with the error.
below is my SQL statement
CurrentDb.Execute "INSERT INTO Kids(ID,First,Last,Age,Gender,Race,Org,School,Address,City,State,Zip,Name_of_Parent_Guardian,Parent_Guardian_Phone,Parent_Guardian_Email_Address,Child_s_Phone,Child_s_Email_Address,Siblings_Who_Participated_in_KIF,Years_Participated_in_KIF,On_Facebook_Y_or_N,On_Pic_Pals_Y_or_N,Notes_Comments,Year" & _
"Value ('" & "','" & Me.First.Value & "','" & Me.Last.Value & "','" & Me.Age.Value & "','" & Me.Gender.Value & "','" & Me.Race.Value & "','" & Me.Org.Value & "','" & Me.School.Value & "','" & Me.Address.Value & "','" & Me.City.Value & "','" & Me.State.Value & "','" & Me.Zip.Value & "','" & Me.NameofparentG.Value & "','" & Me.parentphone.Value & "','" & Me.parentemail.Value & "','" & Me.Child_sphone.Value & "','" & Me.Child_sEmailAddress.Value & "','" & Me.Sibling_s_WhoParticipatedinKIF.Value & "','" & Me.Year_ParticipatedinKIF.Value & "','" & Me.OnFacebook_Y_or_N_.Value & "','" & Me.NotesComments.Value & "','" & Me.Year.Value & "')"
check your syntax ...
it should be like this:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
It cannot be emphasized enough: consider using a parameterized query which avoids quote handling and variable concatenation for a more readable, maintainable, and safer code. Access SQL allows the PARAMETERS clause to specify named parameters with defined types which can be called with a Querydef in VBA.
SQL (save as a stored query in database, adjust types and sizes as needed)
PARAMETERS [IDParam] TEXT(255), [FirstParam] TEXT(255), [LastParam] TEXT(255), [AgeParam] TEXT(255), [GenderParam] TEXT(255),
[RaceParam] TEXT(255), [OrgParam] TEXT(255), [SchoolParam] TEXT(255), [AddressParam] TEXT(255), [CityParam] TEXT(255),
[StateParam] TEXT(255), [ZipParam] TEXT(255), [NameofparentGParam] TEXT(255), [parentphoneParam] TEXT(255),
[parentemailParam] TEXT(255), [Child_sphoneParam] TEXT(255), [Child_sEmailAddressParam] TEXT(255),
[Sibling_s_WhoParticipatedinKIFParam] TEXT(255), [Year_ParticipatedinKIFParam] TEXT(255),
[OnFacebook_Y_or_N_Param] TEXT(255), [NotesCommentsParam] TEXT(255), [YearParam] TEXT(255);
INSERT INTO Kids ([ID], [First], [Last], Age, Gender, Race, Org, School, Address, City, State, Zip,
Name_of_Parent_Guardian, Parent_Guardian_Phone, Parent_Guardian_Email_Address,
Child_s_Phone, Child_s_Email_Address, Siblings_Who_Participated_in_KIF,
Years_Participated_in_KIF, On_Facebook_Y_or_N, On_Pic_Pals_Y_or_N,Notes_Comments, [Year])
VALUES ([IDParam], [FirstParam], [LastParam], [AgeParam], [GenderParam], [RaceParam],
[OrgParam], [SchoolParam], [AddressParam], [CityParam], [StateParam], [ZipParam],
[NameofparentGParam], [parentphoneParam], [parentemailParam], [Child_sphoneParam],
[Child_sEmailAddressParam], [Sibling_s_WhoParticipatedinKIFParam], [Year_ParticipatedinKIFParam],
[OnFacebook_Y_or_N_Param], [NotesCommentsParam], [YearParam]);
VBA (dynamically pass values to named parameters, then execute)
Dim db As Database
Dim qdef As QueryDef
Set db = CurrentDb
Set qdef = db.QueryDefs("myQueryName")
qdef![IDParam] = Me.ID
qdef![FirstParam] = Me.First
qdef![LastParam] = Me.Last
qdef![AgeParam] = Me.Age
qdef![GenderParam] = Me.Gender
qdef![RaceParam] = Me.Race
qdef![OrgParam] = Me.Org
qdef![SchoolParam] = Me.School
qdef![AddressParam] = Me.Address
qdef![CityParam] = Me.City
qdef![StateParam] = Me.[State]
qdef![ZipParam] = Me.Zip
qdef![NameofparentGParam] = Me.NameofparentG
qdef![parentphoneParam] = Me.parentphone
qdef![parentemailParam] = Me.parentemail
qdef![Child_sphoneParam] = Me.Child_sphone
qdef![Child_sEmailAddressParam] = Me.Child_sEmailAddress
qdef![Sibling_s_WhoParticipatedinKIFParam] = Me.Sibling_s_WhoParticipatedinKIF
qdef![Year_ParticipatedinKIFParam] = Me.Year_ParticipatedinKIF
qdef![OnFacebook_Y_or_N_Param] = Me.OnFacebook_Y_or_N_
qdef![NotesCommentsParam] = Me.NotesCommentsParam
qdef![YearParam] = Me.YearParam
qdef.Execute dbFailOnError
Set qdef = Nothing
Set db = Nothing

Run time 3134 error MS Access SQL

Private Sub AddItemButton_Click()
Dim db As Database
Set db = CurrentDb
Dim Item As String
Dim Rate As String
Dim AltRate As String
Dim Reason As String
Dim ApporvedBy As String
Dim Company As String
Dim JobID As String
Me.JobID2 = Me.JobID
db.Execute "INSERT INTO InvItemsRecords (Item, Rate, AltRate, Reason, ApprovedBy, Company, JobID) VALUES ('" & Me.ItemAppendCBO & "', " & Me.RateAppend & ", " & Me.AltRateAppend & ", '" & Me.ReasonAppend & "', '" & Me.ApprovedByAppend & "', '" & Me.Customer & "', " & Me.JobID2 & ")"
Me.AltRate2.Value = Null
End Sub
You should use string literals for your Queries
Dim sqlQuery As String
sqlQuery = "INSERT INTO InvItemsRecords (Item, Rate, AltRate, Reason, ApprovedBy, " & _
"Company, JobID) VALUES ('" & Me.ItemAppendCBO & "', " & Me.RateAppend & ", " & Me.AltRateAppend & ", '" & Me.ReasonAppend & "', '" & _
Me.ApprovedByAppend & "', '" & Me.Customer & "', " & Me.JobID2 & ")"
db.Execute sqlQuery
It makes it a lot easier to debug
INSERT INTO InvItemsRecords (Item, Rate, AltRate, Reason, ApprovedBy, Company, JobID)
VALUES('Some Item', 100, 343, 'Reason A', 'John', 'Jane Doe', Null)
Chances are you are inadvertently passing 1 or more null values to non-nullable fields. Also be careful about the data types. You may need to use CStr(), CInt(), CLong, CDate() or ... to cast your data into the right format If a field can be left blank us NZ().
NZ(Me.RateAppend, True)

error in insert command while inserting data into access database

is this command correct for inserting a single value,
"INSERT INTO test (testname) values ('" & txtSelect.Text & "')"
actually i'm trying to insert via this command, but its not working..
"INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo,
Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem & "', '" &
CmbBedNo.SelectedItem & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" &
txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" &
dtpDate.Value.ToShortDateString & "', '" & cmbBloodGrp.SelectedItem & "', '" &
cmbDoctor.SelectedItem & "', " & txtRemarks.Text & ")"
kindly correct me i'm doing some mistake.
If you posted your entire code - you forgot to actually execute the command. Add
comStudent.ExecuteNonQuery()
before closing the connection.
You should be using Text property of SelectedItem
"INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo,
Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem.Text & "', '" &
CmbBedNo.SelectedItem.Text & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" &
txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" &
dtpDate.Value.ToShortDateString() & "', '" & cmbBloodGrp.SelectedItem.Text & "', '" &
cmbDoctor.SelectedItem.Text & "', " & txtRemarks.Text & ")"
also ToShortDateString is a method and should be writen as ToShortDateString()
no exception is generated, but values are not going to DB.. not stored..
code
Dim RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone, CheckupDate, BloodGroup, Doctor, Remarks As String
RegNo = txtRegNo.Text
BedNo = CmbBedNo.SelectedItem.ToString()
BedType = CmbBedType.SelectedItem.ToString()
Charges = txtCharges.Text
PatName = txtPatName.Text
PatAge = txtPatAge.Text
PatAddr = txtPatAdd.Text
Phone = txtPhone.Text
CheckupDate = dtpDate.Value.ToShortDateString()
BloodGroup = cmbBloodGrp.SelectedItem.ToString()
Doctor = cmbDoctor.SelectedItem.ToString()
Remarks = txtRemarks.Text
conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DBProject\hspms.mdb"
conStudent.Open()
comStudent.CommandText = "INSERT INTO AdmitPt(ID, Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo, Date, BloodGroup, Doctor, Remarks) VALUES('" & RegNo & "', '" & BedType & "', '" & BedNo & "', " & Charges & "', '" & PatName & "', '" & PatAge & "', '" & PatAddr & "', '" & Phone & "', '" & CheckupDate & "', '" & BloodGroup & "', '" & Doctor & "', " & Remarks & ")"
comStudent.Connection = conStudent
comStudent.CommandType = CommandType.Text
conStudent.Close()
code