Solved

Macros, Excel and MSQuery data exchange !

Posted on 2001-06-27
3
206 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now