Solved

Macros, Excel and MSQuery data exchange !

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

815 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

12 Experts available now in Live!

Get 1:1 Help Now