Solved

Macros, Excel and MSQuery data exchange !

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now