Syntax error in the FROM clause
dormdaz
Posted messages
361
Status
Member
-
pijaku Posted messages 13513 Registration date Status Moderator Last intervention -
pijaku Posted messages 13513 Registration date Status Moderator Last intervention -
Hello,
I wrote a small program in VB6 with an Access database. After execution, it shows an error message as follows: [Microsoft][ODBC Access Driver] Syntax error in FROM clause. and the 'Refresh' method of the 'Adodc' object failed.
And the body of the program is as follows:
I really can't solve the problem, thank you in advance and have a good day
Configuration: Windows XP / Firefox 33.0
I wrote a small program in VB6 with an Access database. After execution, it shows an error message as follows: [Microsoft][ODBC Access Driver] Syntax error in FROM clause. and the 'Refresh' method of the 'Adodc' object failed.
And the body of the program is as follows:
Private Sub cmd_chercher_Click() If Me.Tcode.Text = "" Then t = MsgBox("You must enter the code first", vbExclamation + vbOKOnly, "Information") Exit Sub End If Adodc_maj_clients.RecordSource = "SELECT maj_clients.* From maj_clients WHERE (maj_clients.code = '" & Me.Tcode & "')" Adodc_maj_clients.Refresh If Me.Adodc_maj_clients.Recordset.RecordCount <> 0 Then Me.Text11.Text = Me.Adodc_maj_clients.Recordset!nom Me.Text9.Text = Me.Adodc_maj_clients.Recordset!Date_N Me.Text6.Text = Me.Adodc_maj_clients.Recordset!Etat Me.Text5.Text = Me.Adodc_maj_clients.Recordset!Date_RDV '' Me.Text4.Text = Me.Adodc_maj_client.Recordset!Date_Paiement Me.Text3.Text = Me.Adodc_maj_clients.Recordset!N_Recu Me.Text2.Text = Me.Adodc_maj_clients.Recordset!N_reg Me.Text12.Text = Me.Adodc_maj_clients.Recordset!Agence Me.Text3.Text = Me.Adodc_maj_clients.Recordset!Date_Paiement Else p = MsgBox("Search unsuccessful", vbOKOnly + vbInformation, "Information") Exit Sub End If End I really can't solve the problem, thank you in advance and have a good day
Configuration: Windows XP / Firefox 33.0
Related links:
- VBA Syntax for Sheets.Range with Range Variable
- [VBA] : Checking for the presence of a value in a textbox
- Error '9' the index is not part of the selection
- Error, the PasteSpecial method of the Range class failed.
- Conditions for duplicates in the same cell
- Replace & with 1 when entering in the textbox
4 answers
-
Hello,
try this
Tcode is a string
Adodc_maj_clients.RecordSource = "SELECT maj_clients.* From maj_clients WHERE maj_clients.code = " & Me.Tcode
-
Rather difficult to test.
If you start with
" SELECT maj_clients.* From maj_clients"
Does the error occur?
If so, we know that the table name or the connection to the DB is causing the problem.
If not, well we know that it is: WHERE ( maj_clients.code = '" & Me.Tcode & "')
that is causing the problem.
Simplify the code until it works, and add complexities one by one to pinpoint which part is causing the issue.-
Thank you anyway, the problem is not resolved. Here is exactly where my program stops:
Adodc_maj_clients.RecordSource = " SELECT maj_clients.* From maj_clients WHERE ( maj_clients.code = '" & Me.Tcode & "') "
Adodc_maj_clients.Refresh <----------- ( the problem appears here )
If Me.Adodc_maj_clients.Recordset.RecordCount <> 0 Then
.
.
.
I can't solve the problem, I thank you infinitely.
Dorm. -
-
-
-
-
-
Hi,
the syntax of the request is good, but with your VB6 project and the database available at https://www.cjoint.com/ it would be easier.-
I thank you, but the problem I first located when I use Adodc alone with text editors to retrieve data. And when I run it, everything is fine, but when I use the text editor to retrieve the code to search in the table, I am obliged to do these instructions:
Adodc_maj_clients.RecordSource = " SELECT maj_clients.* From maj_clients
WHERE ( maj_clients.code = '" & Me.Tcode & "') "
Adodc_maj_clients.Refresh <--- (the error appears here)
and when I execute the program, it displays an error message:
[Microsoft][ODBC Access Driver] Syntax error in FROM clause. and The 'Refresh' method of the 'Adodc' object has failed.
Please, is there another way to retrieve and display the data? Thank you very much.
Dorm.
-
-
Hello,
Knowing nothing about it, I’ll just throw in my two cents.
Sorry for the inconvenience if this isn’t it, just consider that I was passing by...
Seen on Microsoft.com:If the CommandType of the ADO Data control is set to
adCmdTable, the instruction "SELECT * From" is automatically added to
the RecordSource value. Setting RecordSource to an SQL instruction, such as Select * From Table_name, results in an incorrect SQL instruction like Select * From Select * From Table_name.
To test then:
Adodc_maj_clients.CommandType = adCmdText 'or better: adCmdUnknown Adodc_maj_clients.RecordSource = " SELECT maj_clients.* From maj_clients WHERE ( maj_clients.code = '" & Me.Tcode & "') " Adodc_maj_clients.Refresh
Sources: This very poor translation...
🎼 Best regards,
Franck 🎶-
-
As previously stated, I don't know anything...
Personally, I thought that the "connection" always needed to be declared. A bit like this example:
Private Sub DataGrid1_Error(ByVal DataError As Integer, Response As Integer) Dim MaComm As ADODB.Command, Recup If DataError = 6153 Then Set MaComm = New ADODB.Command 'CONNECTION!!! With MaComm .ActiveConnection = Adodc1.Recordset.ActiveConnection .CommandText = "INSERT INTO Publishers (Name,[Company Name]) VALUES('" & Adodc1.Recordset!Name & "','" _ & Adodc1.Recordset![Company Name] & "')" .Execute .CommandText = "SELECT @@IDENTITY" Recup = .Execute .CommandText = "INSERT INTO Titles (Title,ISBN,[Year Published],PubId) VALUES('" & Adodc1.Recordset!Title & _ "','" & Adodc1.Recordset!ISBN & "','" & Adodc1.Recordset![Year Published] & "','" & Recup(0).Value & "')" .Execute End With Set DataGrid1.DataSource = Nothing Adodc1.Recordset.CancelUpdate Adodc1.Recordset.Requery Set DataGrid1.DataSource = Adodc1 Response = 0 End If End Sub
But, this link might prove useful...
-