S
S
sxaSc2020-03-23 21:28:34
Visual Basic
sxaSc, 2020-03-23 21:28:34

I'm formulating a SQL query in Vba and I'm getting a syntax error in the from clause?

It is necessary to display information about the sellers who completed orders more than the specified number

rs.Open "SELECT [Номер продавца] , Имя,Номер  FROM Заказы, Продавцы " & "COUNT (Номер продавца) " & " group by [Номер продавца] " & " HAVING COUNT[Номер продавца] > " & UserForm2.TextBox1.Text, Conn, adOpenKeyset, adLockOptimistic

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2020-03-24
@BasiC2k

Apparently, you use ADODB connection?
Try not to write a complex query right away, but make it simple, and then complicate it step by step. Only in this way, in the absence of experience, you can find errors in the request itself.
In my opinion, you may have errors in the following places:
- "COUNT (Seller number)" should not be after FROM, because it's not a table;
- UserForm2.TextBox1.Text can contain characters that are not a numeric type to compare against COUNT.
PS When debugging a query, use CopyFromRecordset to display the results and adjust queries.
PPS remember that ADODB in Excel has a number of non-obvious and unpleasant features:
- returns no more than 255 characters from a query to a text field;
- the type of field values ​​is determined based on the contents of the first 10 (sort of) lines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question