How to create a query criteria using VB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I want to create a query criteria ("facturas" or " notas" in "tipo"
column)using VB, could you sendme the code and commands.
TIA
 
I like to run queries in a different way, I create an empty query called
GlobalQuery, and then I assign to it the string I want to run.
e.g

Function aaaaa(ParamNumber as long, ParamString as string )
Dim DBS As Database
Dim rst As Recordset, SqlStr As String

Set DBS = CodeDb
SqlStr = "SELECT * FROM MyTable Where Field1 =" & ParamNumber & " AND Field2
= '" & ParamString & "'"
DBS.QueryDefs("GlobalQuery").SQL = SqlStr

docmd.openquery "GlobalQuery"
End Function
 
Hi, I want to create a query criteria ("facturas" or " notas" in
"tipo" column)using VB, could you sendme the code and commands.

It depends a bit on what you want to do with the records afterwards.

If you want to open a form or a report, attach it to the Filter
parameter:

' create the criterion
strWhere = "Tipo=""facturas"" OR Tipo=""notas"")"

' open the form: I can't remember offhand how many commas to skip,
' check the help file first!
DoCmd.OpenForm strFormName,,strWhere


If you need a recordset to do something with, then you need the whole
command:

strSQL = "SELECT Something, SomethingElse " & _
"FROM MyTable " & _
"WHERE Tipo=""facturas"" OR Tipo=""notas"") " & _
"ORDER BY SomethingElse"

' and get the data
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot, dbForwardOnly)

' and do something
Do While Not rs.EOF
' etc etc


If you just want to see the things in a datasheet (boo, hiss!)

strSQL = "SELECT etc"

Set qdf = db.QueryDefs.Add(strTempQuery) '
qdf.SQL = strSQL
DoCmd.OpenQuerydef strTempQuery

and so on. Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top