473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run the query from excel

112 New Member
Hi,
I have a access database for simple accounts. I want to run the query from my excel sheet and get the result to that respective cells.
My database contains accounts name, type, credit limit, account receivable and account payable.
I can run the query to get any account details from access.

But i need that my manager don;t wana enter into database and run qry and he need get the details in excel sheet.
I had created the excel sheet. that contains account type, credit limit,account receivabale and payable. Additionally i have the dropdown box to select the account name. Actually now i linked with another sheet that gives the data to dropdown. But i need to link with database table. Once the data is selected from dropdown the details of account type ,credit limit, account receivable and payable should change.

Imthiyaz
Dec 7 '06 #1
1 5170
NeoPa
32,557 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. 'These constants are set up for MY usage
  2. 'so won't work directly without modification
  3. Private Const conQryDate As String = _
  4.                   "SELECT [Date] " & _
  5.                   "FROM [tblDate] " & _
  6.                   "WHERE ([Ref]='tblReport')"
  7. Private Const conQryDef As String = "ODBC;" & _
  8.                                     "DSN=MS Access Database;" & _
  9.                                     "DBQ=C:\MyDatabase.Mdb;" & _
  10.                                     "DefaultDir=C:\;" & _
  11.                                     "DriverId=25;" & _
  12.                                     "FIL=MS Access;" & _
  13.                                     "MaxBufferSize=2048;" & _
  14.                                     "PageTimeout=5;"
  15.  
  16. 'GetDataFromAccess regets the data in the current sheet
  17. 'from conQryName in database conDBDir\conDBName.
  18. Private Sub GetDataFromAccess(ranDest As Range, strSQL As String)
  19.     Dim strName As String
  20.     Dim namQuery As Name
  21.     Dim shtOrg As Worksheet
  22.  
  23.     If ranDest.Worksheet.Name <> ActiveSheet.Name Then
  24.         Set shtOrg = ActiveSheet
  25.         Call ranDest.Worksheet.Select
  26.     End If
  27.     strName = "QueryName"
  28.     With ActiveSheet.QueryTables.Add(Connection:=strWork, Destination:=ranDest)
  29.         .CommandText = strSQL
  30.         .Name = strName
  31.         .FieldNames = False
  32.         .RowNumbers = False
  33.         .FillAdjacentFormulas = False
  34.         .PreserveFormatting = False
  35.         .BackgroundQuery = True
  36.         .RefreshStyle = xlOverwriteCells
  37.         .SavePassword = False
  38.         .SaveData = True
  39.         .AdjustColumnWidth = False
  40.         .RefreshPeriod = 0
  41.         .PreserveColumnInfo = True
  42.         Call .Refresh(BackgroundQuery:=False)
  43.         Call .Delete
  44.     End With
  45.     For Each namQuery In ActiveWorkbook.Names
  46.         If InStr(1, namQuery.Name, strName) > 0 Then Call namQuery.Delete
  47.     Next namQuery
  48.     If Not shtOrg Is Nothing Then Call shtOrg.Select
  49. End Sub
  50. '...In the right place in your code
  51.     Call GetDataFromAccess(Range("A1"), conQryDate)
Clearly, this will not work without modification as a lot of the code refers to data and code which you don't have available. I can explain anything you don't understand individually (Don't come back asking me to 'Explain it all').
Dec 7 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3106
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
5
4453
by: deko | last post by:
How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this...
0
4171
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS...
3
11893
by: John | last post by:
Is there a way to code the button that's available in the query window--microsoft excel icon that exports to excel. I know transferspreadsheet will do this---but I want the query, which is in a...
2
1841
by: aland | last post by:
I've got an Excel spread sheet with one row of id's and I'd like to use these in a query and put the results into Excel. Basically I'd like to do something like SELECT txtFileTitle, txtFileYear...
3
4546
by: etwebbox | last post by:
Hoping someone has some ideas on how to solve this issue: I have a macro in excel which runs a query against an Access DB (it actually calls a query inside of Access). The query is not bringing...
19
12720
by: wreckingcru | last post by:
I'm trying to output a SQL query that is constructed thru my VB.net GUI into an excel file. Here is the code I'm using: 'Sqlstmt is the SQL query statement 'Conn is the SQL Connection object...
4
2499
by: torontolancer | last post by:
Hi there how r u .I would really appriciate ur concern regarding checking out this code. its beind a command button and i am have a combo box selecing a query criteria and then pressing the button...
1
10464
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
9
2752
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.