New acces user, defining criteria from VB

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

Guest

Good morning, I asked two days ago about how to design a code in VB that
automatically define a criteria; a code has been sent:
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("Salidas")
qdf.Parameters(0) = "nota"
Set rst = qdf.OpenRecordset(dbOpenSnapshot, dbReadOnly)
rst.MoveLast
rst.MoveFirst

ListBoxName.RowSource="SELECT * FROM Salidas WHERE tipo
IN('facturas', 'notas', 'Sal. Int') "

The problem is that this code doesn’t works; I’m a pretty good VB excels
programmer, but about acces I don’t know a thing.
My query name is “Salidasâ€, I have a column called “Tipo†in this column
exists tree kinds of entries “nota†“factura†and “S.Intâ€, I want to define 4
differents criterias, 1.â€nota†or “factura†2.â€Factura†3.â€Nota†4.â€S.Intâ€
thise criterias are going to be linked to some buttons that I have in a form.

Could you tell me how to use the code attached or suggest me another code,
please remember that I’m just starting to use acces.
TIA
Pd. Also explain me where to put the code.
 
In your query, is the column Tipo identified as a parameter? In other words,
in the Criteria row and Tipo colum of your query, you should have something
like [Enter Tipo]. If you run the query stand alone, an input box should
come up and ask for the parameter value.

Then to run it from a form, you could use a command button for each of your
options or you could use a Combo box that would allow a user to select the
option. The better choice, I think, would be the combo box because you would
have to put the code in only one place. It should be in the After Update
event of the combo box.

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("Salidas")
qdf.Parameters(0) = Me.cboOption
Set rst = qdf.OpenRecordset(dbOpenSnapshot, dbReadOnly)
rst.MoveLast
rst.MoveFirst

I'm not understanding what you are doing with the list box. If that is
something that uses the query after you have made the selection, then there
are a couple of options. If you use the code above, then this should be all
you need:

ListBoxName.RowSource="SELECT * FROM Salidas;"

You could also ignore the code above in your After Update event and change
it to:

ListBoxName.RowSource="SELECT * FROM Salidas WHERE [Tipo] = '" _
& Me.cboOption & "';"

This is untested code, so you may have to tinker with it, but I think the
idea will work.
 
Back
Top