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!
Related
I have a Access form with a bunch of buttons and some text boxes.
The text boxes automatically fill to the table. Thanks to someone else on here I figured out how to sync the button press to the fill the table. Now I need to ensure that the rest of information in the table stays when I press the button and the "Yes" get recorded. Currently all the other column of information doesnt record to the sheet but the button press does. How do I pass by those columns and keep their data and still record the various button presses that need to happen?
Thanks in advance!!
Below is the current button code that records on the table.
Private Sub CWTButton_Click()
Dim Sql As String
Sql = "INSERT INTO [Raw Data] (CWT) VALUES ('Yes');"
CurrentDb.Execute Sql
End Sub`
New Code
Private Sub CWTButton_Click()
Dim Sql As String
Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES ('" & Me!Date.Value & "', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', '" & Me!Length.Value & "', '" & Me!Fish_ID.Value & "','" & Me!Comment.Value & "','Yes');"
CurrentDb.Execute Sql
End Sub
New Code
Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES (#" & Format(Me!Date.Value, "yyyy\/mm\/dd" & "#', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', " & Me!Length.Value & ", " & Me!Fish_ID.Value & ",'" & Me!Comment.Value & "','Yes');"
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"
i have picturebox and a label with path of picture location..
in mysql database i have field 'Photo' with 'Blob' Data Type
and iam using this code to insert data to database :
Try
MysqlCon = New MySqlConnection("Server=" & XIP & ";Database=" & XDB & ";User Id=" & XUser & ";Password=" & XPass & ";")
MysqlCon.Open()
MysqlCmd = New MySqlCommand("INSERT INTO staff(
Full_Name,
Full_Name_T,
Gender,
Num_ID,
Position,
Photo) VALUES
('" & txtfname.Text & "',
'" & txtfnamet.Text & "',
'" & cmbgender.Text & "',
'" & txtnumid.text & "',
'" & cmbposition.Text & "',
'" & lblphotopath.Text & "')", MysqlCon)
MysqlRdr = MysqlCmd.ExecuteReader
MysqlCon.Close()
Catch ex As Exception
Me.Enabled = True
MessageBox.Show(ex.Message & vbNewLine & "Try Again or Call Admin." & vbNewLine & "ERR.06")
Exit Sub
End Try
what iam trying to do is insert image to 'Photo' field using code above.
What should i add to my code above? or what should i change?
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!
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