954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

create a query in access from vb6

hi,
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?????

thanks
mstangeh

mstangeh
Newbie Poster
3 posts since Oct 2005
Reputation Points: 10
Solved Threads: 1
 

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>")
    db.Close
End Sub


Have fun

Yomet

Yomet
Junior Poster
134 posts since Nov 2005
Reputation Points: 16
Solved Threads: 10
 

Hi,

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 :)

Ben-Jammin
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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!!!)

3rd,

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


Good Luck

vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You