Query's in VB code

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

Guest

I was wonderinf if it is possible to do Querys' in VB cod

Basic I have a combo box the has the description of a position and
I want the position ID to come from the query in the cod

Thank
Brando
 
This is from Arvin Meyer, MCP, MVP. Hope it helps

Dim strSQL As String
strSQL = "Delete * From MyTable Where ID =" & Me.txtID
CurrentDB.Execute strSQL

You can also use DoCmd.RunSQL:
DoCmd SetWarning False
DoCmd.RunSQL strSQL
DoCmd SetWarning True

Or you might build a recordset:

Dim rst As DAO.Recordset
Dim db As DAO.Database
Dim strSQL As String

strSQL = "Select * From MyTable"
Set db = CurrentDB
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)

There are multiple ways to do use SQL. For more
information, you might get a copy of John L. Viescas book
"Running Access <version>" which has significant amounts of
SQL.
 
Yes, but they are basically case select of if clauses and
then you have to create the procedure based on the
critiera you put in the select of if clause. Take a look
at the exampls in the VB section of the help and they
should aid you in what you need.
 
Where did you put the code?

If you are going to use the selected value from the list box, I see no
alternative to actually selecting the listbox. You could specifiy a default
value for the list box, and use that value, perhaps.

If you put the code in the Click or AfterUpdate event of the ListBox, then
the event will have to fire for the code to execute. When do you _want_ or
_expect_ the code to execute.

Larry Linson
Microsoft Access MVP
 
Back
Top