VBA - Using GetObject function - get error.
Private Sub cmdbCloseCC_Click() On Error GoTo PROC_ERR
Dim wn As String
wn = "Word.Application"
If Me.IsAppRunning(wn) = True Then
Set wo = Nothing
DoCmd.Close acForm, "frmCC_Status"
Exit Sub PROC_ERR:
Resume PROC_EXIT End Sub ___________________________________________ Function IsAppRunning(ByVal appName) As Boolean
Dim oApp As Object
On Error Resume Next
Set oApp = GetObject(, appName)
'Error here - Run-time error '429':
'ActiveX component can't create object
If Not oApp Is Nothing Then
Set oApp = Nothing
IsAppRunning = True
End If End Function
Thank you for taking the time to report an issue.
What's wrong... Please write below.
I am transfering in data from excel, but it needs manipulation first.
Using Access 2007 and Excel 2007.
Private Sub Command8_Click() On Error GoTo Err_Command8_Click Dim xlsApp As Excel.Application Dim xlswkb As Excel.Workbook Dim f As Object Dim myfile As String Set xlsApp = CreateObject("Excel.Application") Set f = Nothing myfile = ""
Set f = Application.FileDialog(3) f.Title = "SELECT PBUS DATA FILE TO IMPORT" f.AllowMultiSelect = False f.Show With f
myfile = .SelectedItems(1) End With
Set xlswkb = GetObject([myfile])
This basic code right here continues to get hung up on the GetObject
Function RunSalesandOrders() On Error GoTo RunSalesandOrders_Err
DoCmd.OpenQuery "Step 1", acViewNormal, acEdit
DoCmd.Close acQuery, "Step 1" RunSalesandOrders_Exit:
Exit Function RunSalesandOrders_Err:
Resume RunSalesandOrders_Exit End Function
In order to open the query it requires a password however. This is a password required to log on to the Progress OpenEdge Wire Protocol Driver.
My question is - does anyone know how to include the password in the VBA function? I can't use SetWarnings as the password is for an external source
Public Function Foo()
On Error GoTo er
'Code goes here.
ex: 'Cleanup code, closing open objects, etc.
erf 'An error handling function, which writes this function's name
'and error stats to a table, then returns here.
MsgBox Err.Description 'Allows stepping through code in this function.
Resume ex 'Gets cleanup code.
The only issue I'm having is having to pass the current function name in to my error handler. Does anyone know a way to get this systematically
Visual Basic For Applications
MS Access 14.0 Object Library
MS Office 14.0 Access database engine Object Library
MS Excel 14.0 Object Library
MS Outlook 14.0 Object Library
Function IsExcelRunning() As Boolean
Dim xlApp As Excel.Application 'On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
IsExcelRunning = (Err.Number = 0)
Set xlApp = Nothing
Err.Clear End Function
Here is the problem. I am defining a VBA functions called DateDiffW which calculates the number of weekdays (i.e. excludes sat and sun) between 2 dates.
In access 2007, under the "create" tab I clicked "macro" -> "module". Then I defined the function there, starting with:
Function DateDiffW(BegDate, EndDate)
I then saved the module.
In the query, when I call the DateDiffW function I get the error:
"Undefined Function 'DateDiffW' in expression
Option Compare Database Option Explicit
Select Case Month End Function
However when I then run this from a macro I constantly get a message box saying that
"the expression you entered has a function name that the [database] cannot find"
In the macro I have used Run Code with ChangeDataType() as the function name. The module is called
I'm stumped as I have tried every permutation of naming for the function I can think of, but still it sends an error every time.
So what is the best way to let the container sub (that called the function) know about the error that happened in the function? And should the error message be generated in the function or the container sub?
I cannot seem to get the container sub to see the error generated by the function.
Or is there a better way?
eg The last Reading_Number of a Disc_Size 2 is 33
The Disc_Size field is changed from 1.6 to 2 so now the value 34 will be automatically entered into the Reading_Number field.
I'm getting the following error at Private Sub Disc_Size_Change() :
"Compile error: Expected function or variable"
I have other VBA code that runs under certain conditions which I can post if it might be involved.
or in VBA eg:
I get the undefined function error. How do I go about defining a function if necessary?!