-
[RESOLVED] Sql statement
Here`s my problem:
aamort = Application.InputBox("Qual o ano q pretende imprimir?", Type:=1)
strSQL1 = "SELECT ID,descricao,anoaq,valaq FROM tbltransfer where [anoaq]<=" & aamort
strSQL1 = strSQL1 & " order by ID asc"
rs1.Open "tbltransfer", cn, adOpenDynamic, adLockOptimistic, adCmdTable
I want all records with anoaq<=aamort, where aamort is a variable asked at the user.
But this statement returns all records!! :(
why its returning the records with anoaq>aamort
-
Re: Sql statement
Because you are telling it to open a table (tbltransfer) as a table. That means everything in the table comes back
-
Re: Sql statement
You have set up strSQL1, but you aren't using it - the rs1.Open line just uses the table name.
Change it to this:
Code:
rs1.Open strSQL1, cn, adOpenDynamic, adLockOptimistic, adCmdText
-
Re: Sql statement
thanks guys, its working... to
-
Re: Sql statement
As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).