I need to create or replace a permanent query in access (like a view in oracle, postgres...), but from vb6 using ADODB.
i know that i can create and alter tables using a ADODB connection object with something like this

dim obj as new adodb.connection
obj.execute "create table ......:"

but, how to create the views?????


11 Years
Discussion Span
Last Post by vb5prgrmr

Hi ,

Try this out, it worked well when I threw it together. But REMEMBER to read the note in the header... You have been warned... ;)

Public Sub CreateQuery()
'NOTE: this code NEEDS to have a reference to DAO
'      If you already have a reference to ADO be sure
'      to prefix your variable declarations correctly
'      since there are some objects that are the same
'      and you will never know which will be opened
'      unless you prefix them, i.e.
'      Dim ADORecs As ADODB.Recordset
'      Dim DAOResc As DAO.Recordset
    Dim db As DAO.Database
    Dim MyQry As DAO.QueryDef
    Set db = DBEngine.OpenDatabase("<path to your database")
    Set MyQry = db.CreateQueryDef("<Query name>", "<SQL statement>")
End Sub

Have fun




I know this is very late to the original post but I was just wondering if anybody knows how to create a query from the information inputted in textboxes/comboboxes in VB08?

I have a database system in Access but I need to be able to create queries through the information the user inputs in the VB form.

Any help would be great. This is for my A level school project.
Thanks :)


Well Ben, I have some advice for you...

1st, Don't necropost as you have because most everyone who has replied to this thread recieves an email. Instead, create your own thread and if necessary, copy the url of the old dead thread into your new thread posting.

2nd, Make sure you are posting in the right forum as VB.NET 2k8 is a whole different technology that VB6.0... (Which means you have posted in the wrong forum and need to post in the .NET forum in the future!!!)


strSQL = "SELECT * FROM tablename WHERE fieldname = '" & Text1.Text & "'"

Good Luck

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.