Solved

Macros, Excel and MSQuery data exchange !

Posted on 2001-06-27
3
210 Views
Last Modified: 2012-08-13
Hi,

We?re ?desperately trying to perform a task within MS Excel & MS Query.

Transferring data from Query into a spreadsheet is no problem for us.

However we would love to be able to create a Marco which - copies the value of an input cell within Excel,
pastes it into the SQL statement (or a Criteria field) within Query, update the query and refresh the spreadsheet.

We have attempted the above using our database but have found that the Macro fails when Run.

Can anyone help us with this problem ? (None of us here are ?clued up? with VB ? so be gentle !)

We have thought about using DDE but don?t understand this either !!!!!!!!!

The VB routine is shown below (we have made BOLD the first error line) ;


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 27/06/2001 by Neil Booth
'

'
    Range("A1").Select
    Selection.Copy
    With Selection.QueryTable
        .Connection = Array(Array( _
        "ODBC;Driver={SCO Vision ODBC};SERVER=bwt;UID=nab;PWD=katie;Hostname=bwt;ServerID=Informix;DBname=/u1/Strategix/db/tool/baxt;DBuser=;" _
        ), Array("DBauth=;DBoptions=;"))
        .CommandText = Array( _
        "SELECT ndmas.ndm_ndcode, ndmas.ndm_name" & Chr(13) & "" & Chr(10) & "FROM informix.ndmas ndmas" & Chr(13) & "" & Chr(10) & "WHERE (ndmas.ndm_ndcode='ADV001')" _
        )
        .Refresh BackgroundQuery:=False
    End With
End Sub



Yours hopefully,
0
Comment
Question by:NeilBooth
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 75 total points
ID: 6231948
Having created the query once, you don't need to add it again so the macro should read:


   With ActiveSheet.QueryTables(1)
.CommandText = Array( "SELECT ndmas.ndm_ndcode, ndmas.ndm_name" & Chr(13) & "" & Chr(10) & "FROM informix.ndmas ndmas" & Chr(13) & "" & Chr(10) & "WHERE (ndmas.ndm_ndcode='" & Range("A1").Value & "')" )
       .Refresh BackgroundQuery:=False
   End With
End Sub

This will use the value of the cell A1 to filter the returned data.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139909
Hi NeilBooth,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept TimCottee's comment(s) as an answer.

NeilBooth, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7178844
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question