Run time error 3192 Could not find table - database

I am doing a program in Access 2013 and Im trying to make my form insert data into the table (via VBA code), I created a subform (tblClients_subform) containing every "tblClients" data but for some odd reason its throwing me this error:
"Could not find tblClients_subform"
Here is my entire block:
"CurrentDb.Execute "INSERT INTO tblClients_subform (ClientID, ClientName, Gender, " & _
"City, [Address], [Cellphone/Telephone])" & _
"VALUES (" & Me.txtID & ",'" & Me.txtName & "','" & Me.cboGender & _
"','" & Me.txtCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "')"
what I am doing wrong? Is there another way to make my form insert data in the subform table?

Related

Error while passing SQL query using stringbuilder in vb.net

I'm passing some arguments to insert the record into the table using StringBuilder, I' m getting error:
Error 134 Comma, ')', or a valid expression continuation expected.
Near 'napproved' where 'napproved' this is a string argument contains 'N'
Here is the code
sb.Append("insert into [DBAccounting].[dbo].[CRS_TaxReport_TaxConsultant]")
sb.Append(" ([CLIENTCODE],[TC],[SECURITY_NO],[TC_NAME],[ADDRESS],")
sb.Append("[ACCOUNT_NAME],[ACCOUNT_NO],[PHONE_NO],")
sb.Append("[EMAIL_IDS],[IsApproved],")
sb.Append("[ApprovedBy],[ApproveDate],")
sb.Append("[MakerId],[MakerDt])")
sb.Append("VALUES('" & txtclientCode.Text & "',")
sb.Append("'" & txttc.Text & "','" & txtSecNo.Text & "',")
sb.Append("'" & txtTcName.Text & "','" & txtaddress.Text & "','" & txtaccname.Text & "',")
sb.Append("'" & txtaccno.Text & "','" & txtphno.Text & "','" & txtMailID.Text & "',")
sb.Append(" "napproved.ToString" ,"","","approvedby.ToString","Today.ToString")")

Run-time error '3061'. Too few parameters. Expected 1 [duplicate]

This question already has answers here:
run time error "3061" : too few parameters, expected 1
(2 answers)
Closed 7 years ago.
I have the following vb statement at Microsoft Access 2010
CurrentDb.Execute "INSERT INTO Table3(Names,ID, center, village, association , BOD ) " & _
" VALUES(" & Me.fullnametxt & ",'" & Me.worktxt & "','" & _
Me.Combo39 & "','" & Me.assoctxt & "','" & Me.datetraintxt & "','" & Me.datetraintxt & "')"
It generates
Run-time error '3061'. Too few parameters. Expected 1.
You miss some quotes:
CurrentDb.Execute "INSERT INTO Table3 ( Names, ID, center, village, association , BOD ) " & _
" VALUES ('" & Me.fullnametxt & "','" & Me.worktxt & "','" & _
Me.Combo39 & "','" & Me.assoctxt & "','" & Me.datetraintxt & "','" & Me.datetraintxt & "')"

Getting Syntax Error on INSERT INTO command on Visual Basic 2010 to MS ACCESS 2007

I keep getting a syntax error when I run a debug on the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
'Open Connection if not yet Open
cnn.Open() End If
cmd.Connection = cnn
If Me.sn.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO First_Year(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX,SY,CIVIL_STATUS,Religion,Birthdate,TEL_NO,Father,Occupation_F,Mother,Occupation_m,School Last Attended,Address School,Middle_Name)" +
"VALUES ('" & Me.sn.Text & "','" & Me.fn.Text & "','" & Me.ln.Text & "' ,'" & Me.Year.Text & "','" & Me.ed.Value & "','" & Me.s.Text & "','" & Me.sy.Text & "','" & Me.cs.Text & "','" & Me.re.Text & "'," & Me.cn.Text & ",'" & Me.bd.Value & "','" & Me.fa.Text & "','" & Me.fo.Text & "','" & Me.ma.Text & "','" & Me.mo.Text & "','" & Me.lad.Text & "','" & Me.ad.Text & "','" & Me.mi.Text & "')"
cmd.ExecuteNonQuery()
Can some please point out to me whats wrong with it?
You have some fields name that contains spaces. To use these fields names you need to enclose them in square brackets
cmd.CommandText = "INSERT INTO First_Year " & _
"(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX, " & _
"SY,CIVIL_STATUS,Religion,Birthdate,TEL_NO,Father,Occupation_F,Mother, " &
"Occupation_m,[School Last Attended],[Address School],Middle_Name) " &
"...... "
Said that, remember that string concatenations like yours lead to Sql Injection and problem in parsing strings that contains quotes (O'Brien) or decimal numbers or date
Search about Sql Injection and Parameterized queries
A parameterized approach to your query would be
cmd.CommandText = "INSERT INTO First_Year " & _
"(Student_No,Lastname,Firstname,Year_Level,Enroll_Date,SEX, " & _
"SY,CIVIL_STATUS,Religion,Birthdate,TEL_NO,Father,Occupation_F,Mother, " &
"Occupation_m,[School Last Attended],[Address School],Middle_Name) " &
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
cmd.Parameters.AddWithValue("#p1", Me.sn.Text)
cmd.Parameters.AddWithValue("#p2", Me.fn.Text)
... and so on for the remainder 16 parameters placeholders
... respecting their position and converting to the appropriate datatype
you need to remove the space here (in your query) :
......School Last Attended,Address School.......
or write it like this :
..........[School Last Attended],[Address School]..........

error '3075' Syntax error (missing operator) access 2013

The above error is being thrown when I run the below command:
CurrentDb.Execute "INSERT INTO Table2(FirstName, LastName)" & "VALUES('" & Me.frst_Name_txt & ", '" & Me.lst_Name_txt & "','" & "')"
Can anyone see where I am going wrong?
Thanks
The error:
You have extra value '" & "' and also Text data types require delimiters around the value. At its simplest an apostrophe.
Try this
CurrentDb.Execute "INSERT INTO Table2(FirstName, LastName)" & "VALUES('" & Me.frst_Name_txt & "','" & Me.lst_Name_txt & "')"
You're missing an apostrophe: CurrentDb.Execute "INSERT INTO Table2(FirstName, LastName) VALUES('" & Me.frst_Name_txt & "', '" & Me.lst_Name_txt & "')"

number of query values and destination fields are not the same access

When I run this command on my table, it is bringing back the error shown in the title, can anyone see where I am going wrong?
CurrentDb.Execute "INSERT INTO Table2(VolsID, FirstName, LastName)" & _
"VALUES('" & Me.frst_Name_txt & "," & Me.lst_Name_txt & "," & _
Me.vol_ID_txt & "," & "')"
Thanks!
Try this
CurrentDb.Execute "INSERT INTO Table2(VolsID, FirstName, LastName)" & "VALUES('" & Me.frst_Name_txt & "','" & Me.lst_Name_txt & "','" & Me.vol_ID_txt & "')"
Try This. If VolsID is a string field, then wrap it with single quote. e.g. ('" & Me.frst_Name_txt & "')
CurrentDb.Execute "INSERT INTO Table2(VolsID, FirstName, LastName) VALUES (" & Me.vol_ID_txt & ",'" & Me.frst_Name_txt & "','" & Me.lst_Name_txt & "');"

Resources