added to statement and now it doesn't work - ms-access

I'm trying to find where the error is in a SQL statement, but can't seem to locate it. VBA is telling me "Compile error: Mehthod or data member not found" and highlights [RotationalServings7]= '" & Me.Text499 & "' but after looking at it over and over, it seems right to me. Also debug.print mysql2 doesn't give me the shred out showing what it's executing.
side note; it worked just fine until I added all the 9 and 10 items. Looked through the form and all the information is correct, same with the table it's updating.
mysql2 = "UPDATE Thaw_Tags_FTI SET [RotationalItem1]= '" & Me.Combo445.Column(1) & "',[RotationalMeat1]= '" & Me.Text449 & "',[RotationalSS1]= '" & Me.Text452 & "',[RotationalServings1]= '" & Me.Text447 & "',[RotationalItem2]= '" & Me.Combo455.Column(1) & "'," _
& "[RotationalMeat2]= '" & Me.Text459 & "',[RotationalSS2]= '" & Me.Text461 & "',[RotationalServings2]= '" & Me.Text457 & "',[RotationalItem3]= '" & Me.Combo463.Column(1) & "',[RotationalMeat3]= '" & Me.Text467 & "',[RotationalSS3]= '" & Me.Text469 & "'," _
& "[RotationalServings3]= '" & Me.Text465 & "',[RotationalItem4]= '" & Me.Combo471.Column(1) & "',[RotationalMeat4]= '" & Me.Text475 & "',[RotationalSS4]= '" & Me.Text477 & "',[RotationalServings4]= '" & Me.Text473 & "',[RotationalItem5]= '" & Me.Combo479.Column(1) & "'," _
& "[RotationalMeat5]= '" & Me.Text483 & "',[RotationalSS5]= '" & Me.Text486 & "',[RotationalServings5]= '" & Me.Text481 & "',[RotationalItem6]= '" & Me.Combo489.Column(1) & "',[RotationalMeat6]= '" & Me.Text493 & "',[RotationalSS6]= '" & Me.Text495 & "',[RotationalServings6]= '" & Me.Text491 & "'," _
& "[RotationalItem7]= '" & Me.Combo497.Column(1) & "',[RotationalMeat7]= '" & Me.Text501 & "',[RotationalSS7]= '" & Me.Text503 & "',[RotationalServings7]= '" & Me.Text499 & "',[RotationalItem8]= '" & Me.Combo505.Column(1) & "',[RotationalMeat8]= '" & Me.Text509 & "',[RotationalSS8]= '" & Me.Text511 & "',[RotationalServings8]= '" & Me.Text507 & "'," _
& "[RotationalItem9]= '" & Me.Combo778.Column(1) & "',[RotationalMeat9]= '" & Me.Text789 & "',[RotationalSS9]= '" & Me.Text784 & "',[RotationalServings9]= '" & Me.Text780 & "',[RotationalItem10]= '" & Me.Combo787.Column(1) & "',[RotationalMeat10]= '" & Me.Text791 & "',[RotationalSS10]= '" & Me.Text793 & "',[RotationalServings10]= '" & Me.Text789 & "'" _
& "WHERE [ID]=Forms!Thaw_Report_FTI!Combo160"

Related

Input, Edit action in Form Input Data Access 2013

I am writing vba for my work at Banking to manage my data in Access 2013, but i have something wrong when i try to run my code.
File DB here
My code which i used to find out in internet is:
Private Sub cmdthem_Click()
If Me.TXTLCNO.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO db(NOLCTRANSACTION, LCTYPE, LCXKLCNKREF, BENAPPLICANT, AMOUNT, CONTRACTNO, INPUTTER, AUTHORIZER, DATE, STATUS, NOTE) " & _
" VALUES(" & Me.TXTLCNO & ",'" & Me.CBO1 & "','" & _
Me.TXTREF & "','" & Me.TXTBEN & "#,'" & Me.TXTAMOUNT & "',#" & _
Me.TXTCONTRACT & "','" & Me.CBO2 & "','" & Me.CBO3 & "#,'" & Me.TXTDATE & "',#" & _
Me.TXTSTATUS & "','" & Me.TXTNOTE & "')"
Else
'otherwise (Tag of txtID store the id of db to modified)
'CurrentDb.Execute "Update db " & _
" SET NOLCTRANSACTION=" & Me.TXTLCNO & _
", LCTYPE='" & Me.CBO1 & "'" & _
", LCXKLCNKREF='" & Me.TXTREF & "'" & _
", BENAPPICANT='" & Me.TXTBEN & "'" & _
", AMOUNT='" & Me.TXTAMOUNT & "'" & _
", CONTRACTNO='" & Me.TXTCONTRACT & "'" & _
", INPUTTER='" & Me.CBO2 & "'" & _
", AUTHORIZER='" & Me.CBO3 & "'" & _
", DATE='" & Me.TXTDATE & "'" & _
", STATUS='" & Me.TXTSTATUS & "'" & _
", NOTE='" & Me.TXTNOTE & "'" & _
" WHERE NOLCTRANSACTION=" & Me.NOLC.Tag
End If
'clear form
cmdclear_Click
'refresh data in list
db_subform.Form.Requery
End Sub
But when i try to run this command, it always errors statement INSERT INTO db
My table's name is db, it has all fields above
Can you find out my mistake please? Thank you, best regards

Ms-Access Query only allows 255 characters

I am running into an issue for one of my unbound textboxes. Some of my users send out long comments in their "Comment" box and in the database, it only shows 255 characters max. Here is my query to insert the data to the database. It is only the txtComment textbox that I am trying to change.
CurrentDb.Execute _
"INSERT INTO IPA_Raw_Data(Date_IPA, Auditor, Area, Operator, Safely, LineClearance, PPE, VerifyDoc, GVI, CompBefore, NonConf, ProcSteps, Trained, Points, Comments) " & _
"VALUES ('" & Me.txt_Date.Value & "', '" & Me!txt_Name.Value & "', '" & Me!txt_Area.Value & "', '" & Me!txt_Operator.Value & "', '" & Me!cb_Safe.Value & "', '" & Me!cb_LC.Value & "', '" & Me!cb_PPE.Value & "', '" & Me!cb_VDP.Value & "', '" & Me!cb_GVI.Value & "', '" & Me!cb_CBF.Value & "', '" & Me!cb_NC.Value & "', '" & Me!cb_ProStep.Value & "', '" & Me!cb_TrainProc.Value & "', '" & Me!txt_Points.Value & "', '" & Me!txt_Comment.Value & "')"
btn_Clear_Click
Can anyone help me figuring this out please? Thanks!
I had the data type saved to "Short text" rather than "long text" now it works flawlessly!

Access VBA - run time error '3075'

For starters, I have practically no knowledge of VBA Code. What I'm trying to do here is take information from a form and subform and enter it as a new record into a table that is set as the record source of the subform.
The error code reads: run time error '3075':
Syntax Error (Missing Operator) in query expression 'GENERAL METAL (CUBEX)'.
Also I apologize for how messy it is. I honestly just tried to copy what I saw in a YouTube video that kind of represented what I was trying to do.
CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation & _
Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"
This part concerns me:
'" & Me.moldlocation & _ Me.specialconcerns & "'
It looks like you're missing the closing quote before the line suppression. Any time you see "& _" it's telling the code that you're moving to a new line, but to supress that line break when the code is run. You generally need to close up your quotes before you do that, just like was done in the other line suppressor:
qtycast) " & _ " VALUES(
So, in short, give this a shot:
CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation "'," & _
"'" & Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"
Since I don't know your data, I'll just remind you that anything that's TEXT needs to be enclosed with single quotes (i.e. '" & Me.grade & "',) and anything that's an INT does not need the single quote (i.e. " & Me.customer & ",). Just make sure all your variables are enclosed accordingly or that will cause an error as well.
If this answers your question, please don't forget to give the answer a checkmark. Thanks!

How to add a new record from unbound fields of two tables in to a subform

Hey there Good Day can anyone help me please?
I got a mainform and a subform and Ive created a query to join the two tables and ive tried to use the query to insert fields which is unbound, my subform fields which im getting from my join query if I insert into my fields it says and click the Add button I get a error it says:
Run-time error '3134':
Syntax error in insert into statement.
Code I used below:
Private Sub Add_Click()
CurrentDb.Execute "INSERT INTO PlantTransactionQuery(TransactionID,Plant Number,Categories,Description,Location,TransactionDate,Opening_Hours,Closing_Hours,Hours Worked,Fuel,Fuel Cons Fuel/Hours,Hour Meter Replaced,Comments)" & _
"VALUES(" & Me.txt13 & ",'" & Me.txt1 & "','" & Me.txt2 & "','" & Me.txt3 & "','" & Me.txt4 & "','" & Me.txt5 & "','" & Me.txt6 & "','" & Me.txt7 & "','" & Me.txt8 & "','" & Me.txt9 & "','" & Me.txt10 & "'," & Me.txt11 & "," & Me.txt12 & ")"
PlantTransactionsubform.Form.Requery
End Sub
I dont know if u can insert into a query and i dont know which name I must put into brackets for reserved name.
Any help will be much appreciated of how to add two tables in a subform in a button onclick on the same page or even maybe i made a mistake in my code for me everything looks good.
Thanks in advance
You need to put square brackets [] around any table or field name that
contains spaces or "funny characters", or
is an Access reserved word.
Try this instead:
CurrentDb.Execute "INSERT INTO PlantTransactionQuery (TransactionID,[Plant Number],Categories,Description,Location,TransactionDate,Opening_Hours,Closing_Hours,[Hours Worked],Fuel,[Fuel Cons Fuel/Hours],[Hour Meter Replaced],Comments) " & _
"VALUES (" & Me.txt13 & ",'" & Me.txt1 & "','" & Me.txt2 & "','" & Me.txt3 & "','" & Me.txt4 & "','" & Me.txt5 & "','" & Me.txt6 & "','" & Me.txt7 & "','" & Me.txt8 & "','" & Me.txt9 & "','" & Me.txt10 & "'," & Me.txt11 & "," & Me.txt12 & ")"
Edit
You can make SQL statements easier to verify visually if you break them up line-by-line, something like this:
CurrentDb.Execute _
"INSERT INTO [PlantTransactionQuery] (" & _
"[TransactionID], " & _
"[Plant Number], " & _
"[Categories], " & _
"[Description], " & _
"[Location], " & _
"[TransactionDate], " & _
"[Opening_Hours], " & _
"[Closing_Hours], " & _
"[Hours Worked], " & _
"[Fuel], " & _
"[Fuel Cons Fuel/Hours], " & _
"[Hour Meter Replaced], " & _
"[Comments] " & _
") VALUES (" & _
Me.txt13 & ", " & _
"'" & Me.txt1 & "', " & _
"'" & Me.txt2 & "', " & _
"'" & Me.txt3 & "', " & _
"'" & Me.txt4 & "', " & _
"#" & Me.txt5 & "#, " & _
"'" & Me.txt6 & "', " & _
"'" & Me.txt7 & "', " & _
"'" & Me.txt8 & "', " & _
"'" & Me.txt9 & "', " & _
"'" & Me.txt10 & "', " & _
Me.txt11 & ", " & _
Me.txt12 & " " & _
")"
The 3061 error message "Too few parameters..." can happen if a field (column) name is mis-spelled, or a field name that happens to be a reserved word is not enclosed in square brackets. I've edited the query above so all table and column names are bracketed, just to be safe.
Also, check that you are quoting strings and are not quoting numbers. A mistake there could also result in the aforementioned error.
As for [TransactionDate], you probably should un-bind the text box for consistency. Notice that the value for that field is enclosed in hash marks (#) instead of single quotes. You can add a "date" input mask to the text box, or you can use something like...
Format(CDate(Me.txt5), "yyyy-mm-dd")
...to format the date for you.
Finally, be aware that building SQL strings like that leaves you open to SQL injection problems, so you might also consider replacing that .Execute with something like
Dim rst as DAO.Recordset
Set rst = CurrentDB.OpenRecordset("[PlantTransactionQuery]", dbOpenTable)
rst.AddNew
rst![TransactionID] = CLng(Me.txt13)
rst![Plant Number] = Me.txt1
rst![Categories] = Me.txt2
...
rst![Comments] = Me.txt12
rst.Update

execute multiple command in vb together

i am working on a vb project . in this i need to save some record to one table and update some records in another table in one event or click .. i am doing like this .
Conn.Execute "insert into DailyStock(serial,category,model,datee,opnstock,supply,phystk,totalsale,ssale,nsale,totalstock)values(" & txtserial.Text & ",'" & CboCategory.Text & "','" & CboModel.Text & "','" & DTPicker1 & "'," & txtopnstock.Text & "," & txtsupply.Text & "," & txtphystk.Text & "," & txttsale.Text & "," & txtssale.Text & "," & txtnsale.Text & "," & txtstock.Text & ") ; update Menu set phystk=" & txtstock & " where ItemName='" & CboModel & "'"
MsgBox ("Data Saved Successfully")
but it giving error as "character found after sql statement" .. i am not getting where i go wrong .. please help me
You can only run one statement at a time in MS Access. Everything after the ";" is a character found after sql statement.
Conn.Execute "insert into DailyStock(serial,category,model,datee,"_
& "opnstock,supply,phystk,totalsale,ssale,nsale,totalstock)values(" _
& txtserial.Text & ",'" & CboCategory.Text & "','" _
& CboModel.Text & "','" & DTPicker1 & "'," & txtopnstock.Text _
& "," & txtsupply.Text & "," & txtphystk.Text & "," & txttsale.Text & "," _
& txtssale.Text & "," & txtnsale.Text & "," & txtstock.Text & ") "
Conn.Execute "update Menu set phystk=" & txtstock _
& " where ItemName='" & CboModel & "'"