Hello all. I am hoping you can help me with this, I am stumped. Our system generates requests in Excel in a specific format. I created an Excel file with code that lets you select the request you want, and it formats it so it can be imported into access. In my database when the user clicks a button access opens the hidden Excel file, Excel asks them to select which request they want, and access imports the data and closes excel. Everything works great as long as the user doesnt have Excel open. If Excel is open then the hidden file shows up as visible, sometimes it asks which file they want to open multiple times, Access doesnt close the file, and it doesnt import. It also sometimes asks if you want to save the changes to the file. I worked around this by having access check to see if excel is open and then if it is prompting the user to either have access close excel,or to cancel. This is becoming very inconvenient for the end users however, since they have to close excel everytime they want to import a request.
Here is the access vba:
If needed I can add the VBA in Excel to open and format the file, but I think the issue is in Access. Thanks for taking the time to read this and any help you can offer.
Here is the access vba:
Code:
Function GetData()
Dim strMessage As String
Dim intOptions As Integer 'DECLARATION OF VALUES
Dim bytChoice As Byte
'MESSAGE BOX TEXT TO VERIFY ACTION
sApp = "Excel.Application"
If IsAppRunning(sApp) = True Then
strMessage = "THIS WILL CLOSE ALL OPEN EXCEL FILES!!!! PLEASE SAVE AND EXIT EXCEL BEFORE CONTINUING" & _
vbCrLf & "" & _
vbCrLf & "Are you sure you wish to continue?"
intOptions = vbYesNo
bytChoice = MsgBox(strMessage, 20, "Closing.....ALERT!")
If bytChoice = vbYes Then ' IF THEY CHOOSE YES
Call Kill_Excel2
Call sleep1(1)
Call ImportRequestID
Else ' IF THEY CHOOSE NO
TempVars("IDNumber").Value = [Forms]![MainRequestViewForm]![TempReqNum].Value
Exit Function
'DoCmd.RunMacro "Events.Cancel" ' FEATURE IS NOT DELETED
End If
Else
Call sleep1(1)
Call ImportRequestID
End If
End Function
Function ImportRequestID()
On Error GoTo ImportRequest_Err
Dim xlApp As New Excel.Application
Dim CheckDup As Variant
Set xlApp = CreateObject("Excel.Application")
Dim IDNumber As Integer
IDNumber = 0
xlApp.Workbooks.Open "ExcelImportND.xlsm", True, False
Call sleep1(3)
TempVars("IDNumber").Value = xlApp.Worksheets("RequestID").Cells(1, 1).Value
CheckDup = DLookup("[AutoNum]", "[Requests]", "[CGER Ticket] = [TempVars]![IDNumber]")
If TempVars("IDNumber").Value = "" Then
TempVars("IDNumber").Value = [Forms]![MainRequestViewForm]![TempReqNum].Value
GoTo ImportRequest_Exit
End If
If Not IsNull(CheckDup) Then
MsgBox ("This request has been entered.")
GoTo ImportRequest_Exit
Else
DoCmd.RunMacro ("ImportData.ImportRequest")
End If
ImportRequest_Exit:
xlApp.Workbooks.Close
xlApp.Quit
Set xlApp = Nothing
Exit Function
ImportRequest_Err:
MsgBox Error$
Resume ImportRequest_Exit
End Function
If needed I can add the VBA in Excel to open and format the file, but I think the issue is in Access. Thanks for taking the time to read this and any help you can offer.