473,804 Members | 2,124 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 5185
NeoPa
32,579 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
3140
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 SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
5
4481
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 error: Deleting data in a linked table is not supported by this ISAM. From what I understand, indexed sequential access method (ISAM) drivers are used to update "non-Microsoft" file formats. So why doesn't Access
0
4203
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 Excel 2003, I have VBA code that creates and executes queries using the Access database, and returns the results to an Excel sheet. The first time the query is executed, results are returned to Excel in usually less than 10 seconds. However, if the...
3
11935
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 pivot table view, to be exported as a pivot, not just a data list. Does this code exist? Is it transferspreadsheet but with a twist?
2
1864
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 FROM tblFiles WHERE fileID = ! if that makes sense. Any help appreciated -Alan
3
4567
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 back all of the records even though I can run the query directly in Access or Microsoft Query and get all the records returned. For ease of troubleshooting the query can be a simple select * call from the macro to Access. Even with this basic call...
19
12774
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 cmd = New SqlCommand(Sqlstmt, Conn) datareader = cmd.ExecuteReader()
4
2513
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 to take care recoredset from access to excel. i have checked the code in any ways its working fine but when i use the combo box criteria forms!formname!combobox in the query the code breaks down at rst.open a """""""""""gives...
1
10513
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 trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
9
2784
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 from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no data at all that it came from my query named "HVACWindwardQuery" and there's an error on it...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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 we have to send another system
3
3003
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.