473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Excel VBA Query Using Access Database Hangs on 2nd Execute

(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 query is executed a
second time (without closing the Excel workbook), the code hangs at
the line surrounded by "=",s in the code below (this was tested with
message boxes). If the Excel file containing the VBA code is closed
and re-opened the code executes normally.

(Some statements may be unnecessary - they are attempts at resolving
the issue)

Private Sub Execute_Query()
Dim Db As Database
Dim Qd As QueryDef
Dim Rs As Recordset
Dim x As Integer
Const strDatabaseName As String = "My Server Location Goes
Here\AS400 Fields.mdb"

Set Db = Workspaces(0).OpenDatabase(strDatabaseName)
On Error Resume Next
Db.QueryDefs.Delete ("TempQry")
On Error GoTo 0

Set Qd = Db.CreateQueryDef("TempQry", QryStr)
Qd.ODBCTimeout = 0
'================================================= =======
Set Rs = Qd.OpenRecordset()
'================================================= =======
Rs.MoveLast
Rs.MoveFirst

'Read in the field names
With ActiveSheet
For x = 0 To Rs.Fields.Count - 1
.Cells(ActiveCell.Row, x + 1).Value = Rs.Fields(x).Name
Next
End With
Rs.MoveFirst

'Copy the data
ActiveCell.Offset(1, 0).Select
ActiveCell.CopyFromRecordset Rs
Rs.Close
Qd.Close
Db.QueryDefs.Delete ("TempQry")

Db.Close
Set Qd = Nothing

Set Rs = Nothing
Set Db = Nothing

DBEngine.Idle dbFreeLocks
DBEngine.Workspaces(0).Close
End Sub

Several considerations are noted.

The database is compacted and has remained at 16,488KB - no data is
actually stored from Excel queries in the Access database - only
linked tables to the AS400 and the temporary query definition.

I have two computers side by side, both connected to the server.

On computer 1, I opened Excel and the file, ran the code getting
desired results. Without closing Excel or the file, I re-ran the
program and no data or error was returned after an appropriate time -
the hour-glass was displayed. I did not stop the code (this can't be
done with control break), but left Excel and the file "running" and
moved to computer 2.

On computer 2, I opened read-only the same file as on computer 1 from
the server location (only after computer 1 hung-up). I ran the code
and received the same results as were received the first time the code
was run on computer 1, within seconds. The code on computer 2 was
executed again and the computer "hung-up".

Note that both computers were executing the same code from the same
server file, and that both computers were using the same Access
Database on the server. It doesn't appear that an AS400 connection
problem within Access exists - computer 2 was able to use the DB even
while Computer 1 was using it. Both computers are Intel Pentium 4
2.66GH 248MB Windows XP SP1 Office 2003.

I wonder if this is a "memory leak" problem - somewhat similar to the
Microsoft article 319998 concerning Excel sheets? I modified my code
to create a new instance of Excel as per article 246335, but the
problem still occurs. If I manually close the instance of Excel that
ran the VBA, manually open another instance, and re-run the VBA, no
problem seems to occur.

Other MS KB articles discuss problems with linked tables (ID 208379),
but so far, nothing seems to help.

Thanks for your input - any suggestions are appreciated.

Mike
Nov 13 '05 #1
0 4162

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
0
by: franjorge | last post by:
Hi, I have created two stored procedures via VB using this code: sql = "CREATE PROC " & nombre_proc & " AS SELECT *" & _ " From MBM_PUNTOS_SCE_SIN_COINCIDIR_SIEGE_FALTA_PM_NE_" & mes & _ "...
21
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the...
1
by: SteveBark | last post by:
Hello all I am currently trying to develop a script that will take a value from an Excel spreadsheet cell and use that to run a query against an Access table to delete all rows that match the...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
0
NeoPa
by: NeoPa | last post by:
Many of us have noticed that there are some very useful functions available to you when using Excel, but these same functions are not available, as standard, in Access. A particular issue I had...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...
0
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...

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.