editing a query in Access by VB6 code

ktolga
01-12-2004, 04:11 AM
in order to get word report from access in my vb6 program, i create a template query in access's queries tab. vb6 code uses this template query. and i distributed this access file lots of users.
problem is here: i have to add some fields into this query. how can i edit this template query in access database by using vb6? (i must do this process silently. users musn't be known about what changes is being made)

MKoslof
01-12-2004, 07:33 AM
Can we see your code? It is difficult to see what you are doing based on your description. We can provide much more help if we see what your code is trying to do.

Will Cook
01-12-2004, 08:12 AM
VB6 is fairly similar to VBA. Here is how I do it in VBA:
Dim strSql As String
Dim cnn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim cmd As ADODB.Command
strSql = "SELECT .... " & _
"FROM ...." & _
"Where ...."
Set cnn = CurrentProject.Connection
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = cnn
Set cmd = New ADODB.Command
cmd.CommandText = strSql
cat.Views.Delete "YourQuery"
cat.Views.Append "YourQuery", cmd

Note: If your query contains a UNION clause, then this method does not seem to work.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum