Run-Time error '3075' Access - vba

Hey everyone I keep getting the following error, Run-Time error '3075': syntax error in string in query expression "0,")'
CurrentDb.Execute "INSERT INTO MobileDeviceUserList(sUser, sDevice, sMobileNumber, sIMEINumber, sSerialNumber, sAccessories, sNewSIMNumber, sComments, sRecorded) " & _
"VALUES (" & Me.cboDevice & ",'" & Me.cboAccessories & ",'" & Me.txtUser & ",'" & Me.txtNumber & ",'" & Me.txtIMEI & ",'" & Me.txtSerial & ",'" & Me.txtNEWSIM & ",'" & Me.recRecorded & ",'" & _
Me.txtComment & "')"

Start pressing F8 until you reach the problematic string
Press Ctrl + G.
Write exactly this on what you see:
?"INSERT INTO MobileDeviceUserList(sUser, sDevice, sMobileNumber, sIMEINumber, sSerialNumber, sAccessories, sNewSIMNumber, sComments, sRecorded) " & _
"VALUES (" & Me.cboDevice & ",'" & Me.cboAccessories & ",'" & Me.txtUser & ",'" & Me.txtNumber & ",'" & Me.txtIMEI & ",'" & Me.txtSerial & ",'" & Me.txtNEWSIM & ",'" & Me.recRecorded & ",'" & _
Me.txtComment & "')"
The "Debugging" should be quite easy now and the error must be evident.

You are misplacing ticks (e.g. ' ) in the string construction. Probably through copy and paste errors.
Example:
... & ",'" & Me.cboAccessories & ",'" & Me.txtUser & ",'" & Me.txtNumber & ",'" & ...
... should be something closer to,
... & ",'" & Me.cboAccessories & '",'" & Me.txtUser & '"," & Me.txtNumber & ",'" & ...
I cannot supply a foolproff answer as I do not know what fields are text, numeric, dates or memos. Maybe do a string construction into a string var and debug.print the var to see the result.

Related

ACCESS Insert Into issue , unable to update lot of values at once

CurrentDb.Execute "INSERT INTO Data ([Region],[Office],[Employee Name],[Role],[Email ID],[T1 - New File Creation],[T1 - Roll forward],[T1 - Final package (PDF)],[T1 - Final package (paper)],[T1 - Efiling],[T1 - paper filing],[T1 - pre-season package (PDF)],[T1 -pre-season package (paper)],[T1 -FROR Checklist DESC Service check],[T1 - DT1 Intake and Initiate],[T1 - Scan and validate],[T1 - CRA website document downloads (Pulling NOA and other tax)],[T2 -New file creation],[T2 -Roll forward],[T2 -Final package (PDF)],[T2 -Final package (paper)],[T2 -Efiling],[T2 - Returns],[T3 - New file creation],[T3 - Roll forward],[T3 -Final package (PDF)],[T3 -Final package (paper)],[T3 - Net filing],[T3 -Paper filing])" & _
"VALUES ('" & Me.Region.Value & "','" & Me.Office.Value & "','" & Me.Employee_Name.Value & "','" & Me.Role.Value & "', '" & Me.Email_ID.Value & "','" & Me.T1___New_File_Creation.Value & "','" & Me.T1___Roll_forward.Value & "','" & Me.T1___Final_package__PDF_.Value & "','" & Me.T1___Final_package__paper_.Value & "','" & Me.T1___Efiling.Value & "','" & Me.T1___paper_filing.Value & "','" & Me.T1___pre_season_package__PDF_.Value & "','" & Me.T1__FROR_Checklist_DESC_Service_check.Value & "','" & Me.T1___DT1_Intake_and_Initiate.Value & "','" & Me.T1___Scan_and_validate.Value & "','" & Me.T1___CRA_website_document_downloads__Pulling_NOA_and_other_tax_.Value & "','" & Me.T1___CRA_website_document_downloads__Pulling_NOA_and_other_tax_.Value & "','" & Me.T2__New_file_creation & " ','" & Me.T2__Roll_forward & "','" & Me.T2__Final_package__PDF_ & "','" & Me.T2__Final_package__paper_ & "','" & Me.T2__Efiling & "','" & Me.T2___Returns & "'", & _
'" & Me.T3___New_file_creation & "','" & Me.T3___Roll_forward & "','" & Me.T3__Final_package__PDF_ & "','" & Me.T3__Final_package__paper_ & "','" & Me.T3___Net_filing & "','" & Me.T3__Paper_filing & "') ;"
CurrentDb.Execute "INSERT Into Data ([T3 - New file creation],[T3 - Roll forward],[T3 -Final package (PDF)],[T3 -Final package (paper)],[T3 - Net filing],[T3 -Paper filing])" & _
"Values ('" & Me.T3___New_file_creation & "','" & Me.T3___Roll_forward & "','" & Me.T3__Final_package__PDF_ & "','" & Me.T3__Final_package__paper_ & "','" & Me.T3___Net_filing & "','" & Me.T3__Paper_filing & "') & "
CurrentDb.Execute "INSERT INTO Data ([T4_T5 - New file creation],[T4_T5 - Roll forward],[T4_T5 - Final package (PDF)],[T4_T5 -Final package (paper)],[T4_T5 - Netfiling],[T4_T5 - Paper filing])" & _
"Values ('" & Me.T4_T5___New_file_creation & "','" & Me.T4_T5___Roll_forward & "','" & Me.T4_T5___Final_package__PDF_ & "','" & Me.T4_T5__Final_package__paper_ & "','" & Me.T4_T5___Paper_filing & "') & "
CurrentDb.Execute "Insert Into Data ([T3010 - New file creation],[T3010 -Roll forward],[T3010 - Final package (PDF)],[T3010 - Final package (paper)],[T3010 - Paper filing])" & _
"Values ('" & Me.T3010___New_file_creation & "','" & Me.T3010__Roll_forward & "','" & Me.T3010___Final_package__PDF_ & "','" & Me.T3010___Final_package__paper_ & "','" & Me.T3010___Paper_filing & "') & "
CurrentDb.Execute "Insert Into Data ([US tax -Letters(templafy & ms word)],[US tax -Printing/assembly(Dti)],[US tax - Printing/assembly(PDF)],[US tax - Printing/assembly(paper)],[Us tax - Paper filing]) " & _
"Values ('" & Me.US_tax__Letters_templafy___ms_word_ & "','" & Me.US_tax__Printing_assembly_Dti_ & "','" & Me.US_tax___Printing_assembly_PDF_ & "','" & Me.US_tax____Printing_assembly_paper_ & "','" & Me.Us_tax___Paper_filing & "') & "
CurrentDb.Execute "Insert Into Data ([USPT returns -Scan client information to pdf],[USPT returns -Printing/Assembly (CCH Axcess)],[USPT returns- Printing/Assembly (paper)],[USPT returns -Efiling],[USPT returns -Paper filing])" & _
"Values ('" & Me.USPT_returns__Scan_client_information_to_pdf & "','" & Me.USPT_returns__Printing_Assembly__CCH_Axcess_ & "','" & Me.USPT_returns__Printing_Assembly__paper_ & "','" & Me.USPT_returns__Efiling & "','" & Me.USPT_returns__Paper_filing & "') & "
CurrentDb.Execute "Insert Into Data ([GES tax - Finalize and mail],[GES tax - Finalize and pdf],[GES tax - Scanning],[O&E submissions],[EL Draft],[EL Finalize])" & _
"Values ('" & Me.GES_tax___Finalize_and_mail & "','" & Me.GES_tax___Finalize_and_pdf & "','" & Me.GES_tax___Scanning & "','" & Me.O_E_submissions & "','" & Me.EL_Draft & "','" & Me.EL_Finalize & "') & "
When I tried creating only one CurrentDB.Execute to update values it is not happening. When I created multiple currentdb.execute it is only working for the firstone.
Can anyone please modify the currentdb code and help me out.
Insert a DoEvents command before each CurrentDb.Execute or, better, use DAO and the power of Access and open Data as a DAO.Recordset.
Then use methods .AddNew and .Update to insert the seven sets of values - it will run way faster and with much cleaner code than the multiple calls for CurrentDb.Execute and the SQL concatenating.

Insert textbox value from a form into a table

I have a textbox(in form) and a field(in table) both named SerialNumber
This is the control source of the textbox: =([OrderNr] & (""+[Aantal]) & "" & [SapArtNr])
I can't seem to make the textbox save the value inside into the table.
Edit:
Option Compare Database
Private Sub Command82_Click()
' Add data to Table
CurrentDb.Execute "INSERT INTO Geleidelijst(SerialNmbr, InvoerOrderNr, InvoerAantal, InvoerVermogen, InvoerHSLSSpn) " & _
" VALUES(" & Me.SerialNumberLong & ",'" & Me.OrderNr & "','" & _
Me.Aantal & "','" & Me.Vermogen & "','" & Me.HSLSSpn & "')"
End Sub
But then I get error: 3075 Synax error missing operating in query expression. And if I add date as a format it doesn't work either.
Only when it's numbers, but when there's letters and dots and "/" for example, it won't work.
Any help would be nice, thanks.
Most likely, Aantal is numeric, so try without quotes:
CurrentDb.Execute "INSERT INTO Geleidelijst " & _
"(SerialNmbr, InvoerOrderNr, InvoerAantal, InvoerVermogen, InvoerHSLSSpn) " & _
"VALUES('" & Me.SerialNumberLong & "','" & Me.OrderNr & "'," & Me.Aantal & ",'" & Me.Vermogen & "','" & Me.HSLSSpn & "')"

Access 2016 Error 3464 while coding for Update button

In access 2016 I'm trying to use an update command.I'm creating a database as my internship project as I'm unfamiliar with the coding I have been struggling a lot. I'm referring to a video by Setha Iech: https://www.youtube.com/watch?v=Ri2Y9-16AEo. When I'm using the below code an error continuously pops up
Error 3464
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO Business(ID, Project_ID, [Date_of_Enquiry], Division, Client, Description, Probability_to_win,Status, [Proposal_Submission_date], [Expected_award_date], Remarks)" & _
"VALUES ('" & Me.txtID & "','" & Me.txtProject_ID & "','" & Me.txtDate_of_Enquiry & "','" & Me.cboDivision & "','" & _
Me.txtClient & "','" & Me.txtDescription & "','" & Me.cboProbability_to_win & "','" & Me.cboStatus & "','" & Me.txtProposal_Submission_date & "','" & Me.txtExpected_award_date & "','" & Me.txtRemarks & "')"
Else
'otherwise (Tag of txtID store the ID of statement to be modified)
CurrentDb.Execute "UPDATE Business" & _
" SET ID=" & Me.txtID & _
", Project_ID='" & Me.txtProject_ID & "'" & _
", Date_of_Enquiry='" & Me.txtDate_of_Enquiry & "'" & _
", Division='" & Me.cboDivision & "'" & _
", Client='" & Me.txtClient & "'" & _
", Description='" & Me.txtDescription & "'" & _
", Probability_to_win='" & Me.cboProbability_to_win & "'" & _
", Status='" & Me.cboStatus & "'" & _
", Proposal_Submission_date='" & Me.txtProposal_Submission_date & "'" & _
", Expected_award_date='" & Me.txtExpected_award_date & "'" & _
", Remarks='" & Me.txtRemarks & "'" & _
" WHERE ID=" & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
databasesub.Form.Requery
End Sub
Thank you for your answers in advance

How to insert into a table while ignoring fields with no data?

I wan't to insert data to a table but not all fields are required to be filled some are just optional.
CurrentDb.Execute "INSERT INTO tbl_Records_of_Violation(Serial_Number,Badge,Rank,Lastname,Firstname,Middlename,Qualifier,Gender,Birthdate,Date_Ent_Svc,Address,MotherUnit,Unit,Date_of_Commission,Reporting_Officer,Report_to_Supervisor,Approving_Authority,Punishment,Remarks,Violation1) VALUES ('" & Me.Serial_Number & "','" & Me.Badge & "','" & Me.Rank & "','" & Me.Lastname & "','" & Me.Firstname & "','" & Me.Middlename & "','" & Me.Qualifier & "','" & Me.Gender & "','" & Me.Birthdate & "','" & Me.Date_Ent_Svc & "','" & Me.Address & "','" & Me.MotherUnit & "','" & Me.Unit & "','" & Me.Date_of_Commission & "','" & Me.Reporting_Officer & "','" & Me.Report_to_Supervisor & "','" & Me.Approving_Authority & "','" & Me.Punishment & "','" & Me.Remarks & "'," & Me.Violation1 & ")"
MsgBox "Record has been updated", vbInformation, "Record Information"
I want that even if one of the field is empty it would be saved in my table.
The table tbl_Records_of_Violation has 20 columns of data being inserted by this command.
Each of those 20 columns should be defined as Nullable,
and each of the screen values (Me.xxx) needs to have valid data or nulls.

Operator '&' is not defined for string "Insert into Table_Name(XYZ_" and type 'Byte()'

I get this error →
Operator '&' is not defined for string "Insert into SP_Master_Entry (SP_" and type 'Byte()'.
I think this error is caused near dr(SP_Photo) and am very much new to VB.NET
mainModule.DatabaseNonQuery("
Insert into SP_Master_Entry
(SP_ID, SP_Name, Gender, Date_Of_Birth, Date_Of_Join, Branch_ID,
SP_Area_ID, SP_Address1, SP_Address2, SP_Address3, PIN, Qualification,
Contact_Number, SP_Photo, SP_Status, Caste, SHG_Member, Marital_Status,
Salary, KYC_TYPE_ID, KYC_Code, Reference, Reference2, Agreement, Resigned,
ResignedDate,delivery_status,allow_edit)
VALUES (" & dr("SP_ID") & ",'" & dr("SP_Name") & "','" & dr("Gender") & "','"
& dr("Date_Of_Birth") & "','" & dr("Date_Of_Join") & "',"
& dr("Branch_ID") & "," & dr("SP_Area_ID") & ",'" & dr("SP_Address1")
& "','" & dr("SP_Address2") & "','" & dr("SP_Address3") & "',"
& dr("PIN") & "," & dr("Qualification") & ",'" & dr("Contact_Number")
& "'," & dr("SP_Photo") & ",'" & dr("SP_Status") & "','" & dr("Caste")
& "','" & dr("SHG_Member") & "','" & dr("Marital_Status") & "','"
& dr("Salary") & "'," & dr("KYC_TYPE_ID") & ",'" & dr("KYC_Code")
& "','" & dr("Reference") & "','" & dr("Reference2") & "','"
& dr("Agreement") & "','" & dr("Resigned") & "','" & dr("ResignedDate")
& "','" & dr("delivery_status") & "','" & dr("allow_edit") & "','"
& Today.Date.ToString & "','" & Today.Date.ToString & "')")
The error says it all: Byte() (i.e. an array of bytes) is a fundamentally different type from String and you cannot concatenate the two. How to solve this depends on what data these bytes contain and what you want to get from them. The Encoding.GetString method may help, if the bytes contain encoded text data.
More generally, the code you posted is beyond the pale. You cannot write code like this, it’s completely unreadable and hence worthless. Refactor it.
Before inserting an image.
Convert to byte array,i.e dim imgbyte as byte=datarow("Your Photo column")
Then convert/build a Memory Stream and build image for the memory stream
Now use the image which you have build and use it in insert query as shown below
Dim img_b As Byte() = dr("SP_Photo")
Dim img_stream As IO.MemoryStream
img_stream = New IO.MemoryStream(img_b)
Dim img As Image = Image.FromStream(img_stream)
Dim cmd As New SqlCommand("update user_table_name set user_Photo=#image where user_ID=" & dr("SP_ID"), connstr)
cmd.Parameters.Add("#image", SqlDbType.Image, img_b.Length).Value = img_b
cmd.ExecuteNonQuery()