Topics Search

VBA - Using GetObject function - get error.

VBA - Using GetObject function - get error.
Views: 44
I have an MS Access application and it opens a file from MS Word. Before I close the MS Access form, I need to programmatically determine if the MS Word application is running. I use the following sub and function:

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
End If
DoCmd.Close acForm, "frmCC_Status"
Application.Quit PROC_EXIT:
Exit Sub PROC_ERR:
MsgBox Err.Description
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
Debug.Print oApp
If Not oApp Is Nothing Then
Set oApp = Nothing
IsAppRunning = True
End If End Function
Sponsored Links:

Similar posts...


Inside Access 2007 open Excel

Inside Access 2007 open Excel Icon
I am looking for the VBA code that will let me open an excel workbook and run a macro in it then close the workbook.
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

Include Password in VBA for ODBC Connection

Include Password in VBA for ODBC Connection Icon
I have a query that pulls from an external database via an ODBC Connection. This is the VBA for running and closing the query:

Function RunSalesandOrders() On Error GoTo RunSalesandOrders_Err
DoCmd.OpenQuery "Step 1", acViewNormal, acEdit
DoCmd.Close acQuery, "Step 1" RunSalesandOrders_Exit:
Exit Function RunSalesandOrders_Err:
MsgBox Error$
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

Want function to get current function name

Want function to get current function name Icon
I am developing an all-purpose error handler. As I see it, the "ideal" function would look like this:

Public Function Foo()
On Error GoTo er
'Code goes here.
ex: 'Cleanup code, closing open objects, etc.
Exit Function
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.
End Function

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

Run-time '429': ActiveX component can't create object

Run-time '429': ActiveX component can't create object Icon
I have the below function that always crashes on the highlighted line. I have the following libraries added.Help please.

Visual Basic For Applications
MS Access 14.0 Object Library
OLE Automation
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

Where to define VBA Functions?

Where to define VBA Functions? Icon
Where do I define a user-defined VBA functions so that I can call them in the query?

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

Compile Error: Argument Not Optional

Compile Error: Argument Not Optional Icon
I am trying to create the ACCDE front end but I am running into errors creating it. This led me into compiling my VBA code and I get the "Argument Not Optional" error highlight "Month" in the Function below. This function is used in Access while running a make table query.

Option Compare Database Option Explicit
Function LoadFactor1to12()
Select Case Month End Function

Module Error in Macro

Module Error in Macro Icon
I have created a module as below, which when I use Run in the VBA window does exactly what I want it to.
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.

VBA Compile error: Expected function or variable

VBA Compile error: Expected function or variable Icon
I want the SQL code to get the last Reading_Number of a certain Disc_Size when the Disc_Size field is changed.

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.

Passing Errors from Functions to Containing Sub

Passing Errors from Functions to Containing Sub Icon
I'm using MS Access 2003. I have some validation code that I'd like to make into a function because the code will be used in multiple places. I'm thinking that if an error happens in the validation function, I want the calling sub to know about that.

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?

FileLen - Why do I get an 'Undefined Function' error?

FileLen - Why do I get an 'Undefined Function' error? Icon
I want to record the size of a file and have tracked down plenty of posts which suggest that 'FileLen' is the function that I need. However, whether I use it a query eg:

file_len_1: FileLen("C:\test.txt")

or in VBA eg:

Msgbox FileLen("C:\test.txt")

I get the undefined function error. How do I go about defining a function if necessary?!