473,581 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access hangs

Hello all,
I am trying to import the contents of an Excel sheet into my Access
Database. When clicking the button excel opens allright and does what I
programmed (the cells get updated with the value "Geimportee rd" ("Imported"
in English). So I get to the excel file alright but after changing the cells
to "Geimportee rd" Access hangs. When viewing the task manager it says that
the CPU activity is 100% and the only way to get out of this is the three
finger solution. I have putthe code below, can anybody help me with this?

Many thanks,

Ronny
*************** *************** *************** ****
Public Declare Function FindWindow Lib "user32" Alias "FindWindow A"
(ByVallpClassNa me As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32.dll " Alias "SendMessag eA"
(ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As
Long
*************** *************** *************** ****
Public Function DetectExcel()
' Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow("XLM AIN", 0)
If hWnd = 0 Then ' 0 means Excel not running.
Exit Function
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Function
*************** *************** *************** *****
Private Sub btnImportTGAFFG _Click()
Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunn ing As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyXL = GetObject(, "Excel.Applicat ion")
If Err.Number <> 0 Then ExcelWasNotRunn ing = True
Err.Clear ' Clear Err object in case error occurred.

' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel

' Declare Integers with 'n' = the same name as the field to reference the
columns
Dim nGeslacht As Integer, nTaal As Integer, nAanspreking As Integer, nNaam
As Integer, nVoornaam As Integer, nStraat As Integer
Dim nHuisnr As Integer, nPostcode As Integer, nGemeente As Integer,
nProvincie As Integer, nLand As Integer, nEmailadres
Dim nUrl As Integer, nTelefoon As Integer, nGsm As Integer, nFax As Integer,
nNote As Integer, nRow As Integer

Dim sEmailadres As String

nGeslacht = 4
nTaal = 1
nAanspreking = 3
nNaam = 5
nVoornaam = 6
nStraat = 8
nHuisnr = 9
nPostcode = 10
nGemeente = 11
nProvincie = 12
nLand = 13
nEmailadres = 2
nUrl = 17
nTelefoon = 14
nGsm = 15
nFax = 16
nNote = 7

nRow = 3

sEmailadres = "X" 'Serves to start loop
' Show Microsoft Excel through its Application property. Dan
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.

MyXL.Applicatio n.Visible = True
MyXL.Parent.Win dows(1).Visible = True

'Set the object variable to reference the file you want to see.
Set MyXL = GetObject("MyPa th\Myfile.XLS")
'Do manipulations of the file here.

Dim db As ADODB.Recordset
Set db = CurrentProject. Connection.Exec ute("SELECT * " & "FROM tblDhscmails
") _
'& "WHERE Docname IS NOT NULL " _
'& "ORDER BY ID;")
Do While Nz(Trim(sEmaila dres)) <> ""
If Nz(Trim(MyXL.Ap plication.Cells (nRow, nEmailadres).Va lue)) <> "" Then
db.AddNew
db!Taal = Nz(Trim(MyXL.Ap plication.Cells (nRow, nTaal).Value))
MyXL.Applicatio n.Cells(nRow, nTaal).Value = "Geimportee rd!"
db!Geslacht = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nGeslacht).Valu e))
MyXL.Applicatio n.Cells(nRow, nGeslacht).Valu e = "Geimportee rd!"
db!Aanspreking = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nAanspreking).V alue))
MyXL.Applicatio n.Cells(nRow, nAanspreking).V alue = "Geimportee rd!"
db!Naam = Nz(Trim(MyXL.Ap plication.Cells (nRow, nNaam).Value))
MyXL.Applicatio n.Cells(nRow, nNaam).Value = "Geimportee rd!"
db!Voornaam = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nVoornaam).Valu e))
MyXL.Applicatio n.Cells(nRow, nVoornaam).Valu e = "Geimportee rd!"
db!Straat = Nz(Trim(MyXL.Ap plication.Cells (nRow, nStraat).Value) )
MyXL.Applicatio n.Cells(nRow, nStraat).Value = "Geimportee rd!"
db!Huisnr = Nz(Trim(MyXL.Ap plication.Cells (nRow, nHuisnr).Value) )
MyXL.Applicatio n.Cells(nRow, nHuisnr).Value = "Geimportee rd!"
db!Postcode = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nPostcode).Valu e))
MyXL.Applicatio n.Cells(nRow, nPostcode).Valu e = "Geimportee rd!"
db!Gemeente = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nGemeente).Valu e))
MyXL.Applicatio n.Cells(nRow, nGemeente).Valu e = "Geimportee rd!"
db!Provincie = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nProvincie).Val ue))
MyXL.Applicatio n.Cells(nRow, nProvincie).Val ue = "Geimportee rd!"
db!Emailadres = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nEmailadres).Va lue))
'Loop will continue until sEmailadres = ""
sEmailadres = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nEmailadres).Va lue))
MyXL.Applicatio n.Cells(nRow, nEmailadres).Va lue = "Geimportee rd!"
db!Telefoon = Nz(Trim(MyXL.Ap plication.Cells (nRow,
nTelefoon).Valu e))
MyXL.Applicatio n.Cells(nRow, nTelefoon).Valu e = "Geimportee rd!"
db!GSM = Nz(Trim(MyXL.Ap plication.Cells (nRow, nGsm).Value))
MyXL.Applicatio n.Cells(nRow, nGsm).Value = "Geimportee rd!"
db!Fax = Nz(Trim(MyXL.Ap plication.Cells (nRow, nFax).Value))
MyXL.Applicatio n.Cells(nRow, nFax).Value = "Geimportee rd!"
db!Note = Nz(Trim(MyXL.Ap plication.Cells (nRow, nNote).Value))
MyXL.Applicatio n.Cells(nRow, nNote).Value = "Geimportee rd!"
db.Update
End If
nRow = nRow + 1
Loop

' If this copy of Microsoft Excel was not running when you
' started, close it using the Application property's Quit method.
' Note that when you try to quit Microsoft Excel, the
' title bar blinks and a message is displayed asking if you
' want to save any loaded files.
If ExcelWasNotRunn ing = True Then
MyXL.Applicatio n.Quit
End If

Set MyXL = Nothing ' Release reference to the
' application and spreadsheet.
db.Close
End Sub
Nov 12 '05 #1
1 2751
Ronny Sigo wrote:
Hello all,
I am trying to import the contents of an Excel sheet into my Access
Database. When clicking the button excel opens allright and does what I
programmed (the cells get updated with the value "Geimportee rd" ("Imported"
in English). So I get to the excel file alright but after changing the cells
to "Geimportee rd" Access hangs. When viewing the task manager it says that
the CPU activity is 100% and the only way to get out of this is the three
finger solution. I have putthe code below, can anybody help me with this?

Many thanks,


I would open up your code and click on the bar to step through your code
to find out where it aborts. Or do something like this

db!Geslacht = Nz(Trim(...
MyXL.Applicatio n.Cells...
msgbox "Geslaccht"
db!Aanspreking = NZ(Trim(...
MyXL.Applicatio n.Cells(...
msgbox "Aansprekin g"

In other words, find out where it stops computing. Also, take out the
OnError statement if you have one.

Next, you are assigning the word "Imported" to each row/col as it is
imported. What if a column is set up as a date or number field?

Is it possible that you could set up a link between the Excel
spreadsheet and Access? That way the spreadsheet would simply be
another table in Access and could be updated either in Excell or in
Access. (File/GetExternalData/Link...set filetype to Excel, select
Excel file)
Nov 12 '05 #2

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

Similar topics

1
3142
by: szudor | last post by:
Hi, When I start db2cc, the program hangs with memory access violation in javaw.exe. Strating with trace option, in java trace file I found the following information: 0SECTION TITLE subcomponent dump routine NULL =============================== 1TISIGINFO signal 11 received 1TIDATETIME Date: ...
1
3607
by: Setya Nugraha Djajadinata | last post by:
Hi all, I try to open an mdb and it gives error message : The database 'c:\MyDB\PDz.mdb' needs to be repaired or isn't a database file. You or another user may have been unexpectedly quit Microsoft Access while a Microsoft Access database was open. Do you want Microsoft Access to attempt to repair the database ?
1
425
by: Ronny Sigo | last post by:
Hello all, I am trying to import the contents of an Excel sheet into my Access Database. When clicking the button excel opens allright and does what I programmed (the cells get updated with the value "Geimporteerd" ("Imported" in English). So I get to the excel file alright but after changing the cells to "Geimporteerd" Access hangs. When...
0
1591
by: Robert Langen | last post by:
I'm calling an Access XP application from an Outlook XP appointment form. Everything works, but the lines DoCmd.OutputTo acOutputReport, "testreport", acFormatRTF, "c:\test.rtf", False Docmd.Quit produce Access hangs. That means, the file testreport.rtf is correctly created, but Access doesn´t quit. The process msaccess.exe stays and...
11
4039
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000...
0
4182
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...
6
7302
by: Nick via AccessMonster.com | last post by:
Hello all, I've been working on a VBA application in Access for a few months now. This morning, my Access application began to hang in memory, using 97-100% of the CPU, and the only way to remove it is through the Task Manager. I'm using an Application.Quit command, which worked fine yesterday, but doesn't close the instance anymore. I...
1
3825
by: TD | last post by:
I have the code below under a button on a form. At this point am just testing how to send email from MS Access. Access is installed on a machine running WinXP Pro. I checked the box next to Microsoft CDO for Windows 2000 under References. I can send one message and then if can close Access no problems. If I click the button several times...
4
2817
by: MrDeej | last post by:
Hello! I have a complex .accdb database which i after yesterdays changes cannot enter the VBA anymore. Most of the forms and all tables/queries works fine. But one of the forms causes it to hang and everytime i try to enter VBA it hangs so i cant find a way to fix it. I belive that it corrupts in some of the code i wrote yesterday. This is...
0
7789
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
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. ...
1
7894
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5670
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...
0
3803
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...
1
2300
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
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1132
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...

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.