473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Outlook/Access connection help

4 New Member
Please help! I have an Outlook module opening a connection to Access, writing in some data, and then pulling out some data. But for some reason the code only works the first time and after that you have to close outlook and reopen it for it to work. After you run the code you can not even open the Access database until you close Outlook. I suspected it was a problem with the connection not being closed, or closed correctily, but I have tried every thing I can find on how to clean up at the end with no luck. Here is the code.

The code in my error handler also fires every run if I have it active, but with no error description or anaything. that is not my big concern though.

Expand|Select|Wrap|Line Numbers
  1. Sub GetTickets()
  2.     'On Error GoTo ErrHand:
  3.  
  4.     Dim StrTmp As String
  5.     Dim Filez() As String
  6.     Dim EmlAdd() As String
  7.     Dim TckNum() As String
  8.     Dim TicDir As String
  9.     Dim NumFiles As Long
  10.     Dim i As Long
  11.     Const acAppendData = 2
  12.     Dim AccApp As Access.Application
  13.  
  14.     TicDir = "C:\Documents and Settings\g43692\Desktop\Jeff's Stuff\Ticketing System\"
  15.  
  16.     Set AccApp = CreateObject("Access.Application")
  17.     AccApp.OpenCurrentDatabase TicDir & "Tickets.mdb"
  18.     StrTmp = Dir$(TicDir & "Tickets\*.xml")
  19.  
  20.     Do While Len(StrTmp)                                                 'Get all file names
  21.         NumFiles = NumFiles + 1
  22.         ReDim Preserve Filez(1 To NumFiles)
  23.         Filez(NumFiles) = StrTmp
  24.         StrTmp = Dir$()
  25.         'MsgBox Filez(NumFiles) & NumFiles
  26.     Loop
  27.  
  28.     If (NumFiles > 0) Then
  29.         ReDim EmlAdd(1 To NumFiles)
  30.         ReDim TckNum(1 To NumFiles)
  31.  
  32.         For i = 1 To NumFiles                                            'Import XML for all files into Access
  33.             AccApp.ImportXML DataSource:=TicDir & "Tickets\" & Filez(i), ImportOptions:=acAppendData
  34.             TckNum(i) = DMax("TicketNumber", "Tickets")
  35.             EmlAdd(i) = DMax("Email", "Tickets", "TicketNumber = " & TckNum(i))
  36.             MsgBox "Email: " & EmlAdd(i) & ", Ticket #:" & TckNum(i)
  37.         Next
  38.  
  39.         'Kill (TicDir & "Tickets\" & "*.xml")
  40.     End If
  41.  
  42.     Erase Filez()
  43.     Erase EmlAdd()
  44.     Erase TckNum()
  45.     AccApp.CloseCurrentDatabase
  46.     Set AccApp = Nothing
  47. 'ErrHand:
  48.     'AccApp.CloseCurrentDatabase
  49.     'MsgBox "ERROR: " & Err.Description
  50.     'Exit Sub
  51. End Sub
  52.  
  53.  
Sep 29 '09 #1
2 2432
Dököll
2,364 Recognized Expert Top Contributor
Have you tried using Debug, and step through it?
Nov 9 '09 #2
jrworsham
4 New Member
Thanks for the tip I actually figured it out. I needed to add a line to refresh the current database before DMax would work the second time. Don't know why this would be needed. DMax seems to have a lot of quirks.
Nov 11 '09 #3

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

Similar topics

0
1721
by: Alfred | last post by:
Hi I am using following code to send email How can I use the .body or .htmlbody to insert a picture in the body of ms outlook. Outlook makes provision for sending pictures. If you are in the...
3
2340
by: Strasser | last post by:
In Access2000 mass emailing worked perfectly (very powerful tool!). Doesn't work when using XP version of both Access and Outlook, even though I checked the box to ensure that I was sending the...
7
3589
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i...
2
10509
by: mik.sjoblom | last post by:
Hello, I have developed a Access application that needs to read mail from Outlook, versions on Access and outlook are 2003. In the code i use mapi to connect to outlook. When i tries to read the...
2
4120
by: Ecohouse | last post by:
I've written a function to check emails in Outlook using Access which works. But I need to be able to have it work for different version of Outlook. I'm using Outlook 2002 and I need to also work...
3
4535
by: =?Utf-8?B?RmxpcGNoaXA=?= | last post by:
Having recently moved to broadband and using Outlook Express to manage my emails, I have encounter a problem with sending emails although I can receive all emails. The following error message...
2
3629
by: obroie | last post by:
Hi all, I am trying to move emails from Outlook into an Access table, the code below worked for me before, but now I am having a problem as this error message comes up: Run-time error 438 'Object...
0
820
by: atishrg | last post by:
Hi Guys, I need some help from you, I am creating vb.net application which uses a outlook addin, I am checking exchange server connection with outlook, if this connection is established then mail...
23
5929
by: andyoye | last post by:
How can I launch Outlook on users machines when they click a button on a web form (InfoPath)? Thanks
0
7216
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,...
0
7098
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...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
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
5613
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,...
1
5028
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
3187
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
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.