I am getting "Object Does Not Source Automation Events "
on the following VB 6.0 line
Public WithEvents conn As Connection
Please Help
Maybe you have another class called Connection? From another library or from your own code? I assume you want an ADO connection, try forcing it
Public WithEvents conn As ADODB.Connection
Related
My question is about absolute control over automated instances. I'm using VB6 to automate the generation of forms used in our workplace. The app is in Beta and I've written a User Manual to introduce the application to new users; explaining the sub-functions of the GUI. I use a command button on the GUI to open and close the User Manual in an instance of Word. All this is fine until the user closes the Word app manually while the app is running. This kills the Word instance, but I need to either stop the user from closing the Word instance, or have the app realize the instance is gone. My automation knowledge is pretty shallow. I adapt sub routines from VBA macros. Please help.
I need to either stop the user from closing the Word instance, or have
the app realize the instance is gone
You can do both - declare your Word variable using the "Give me events" syntax and it will raise the DocumentBeforeClose event in your code.
Public WithEvents mWordApp As Word.Application
Sub DoStuff()
Set mWordApp = New Word.Application
'// open doc ...
mWordApp.Visible = True
End Sub
Private Sub mWordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
Cancel = MsgBox("Word is closing, keep open?", vbYesNo) = vbYes
End Sub
The "... WithEvents ..." declaration of the MSOffice Application instance is the solution to this problem. The event list for the app allows the programmer full automated control of the instance from behind the curtain. Thanks all!
I am very new to vbscript. My task is to create an excel sheet whenever the new mail comes in . I just want new excel and it should have only 2 fields Subject and Sender. That too only the most recent record .
Any help in this direction is really appreciated
To handle new mail items you can handle the NewMailEx event of the Application class or just create a rule and then assign a macro sub to run when the rule is triggered. The VBA macro should look like the following one:
public sub test(mail as MailItem)
' do whatever you need
end sub
Then you can automate Excel to get the job done. I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.
We have a fairly large Access front-end application that has been running on Access 2010. It makes extensive use of ADO recordsets for accessing data on our SQL servers, and frequently uses the UniqueTable form property.
We are looking to move the whole office to Office 2013 early next year, but during testing we have found that Access 2013 will not work with our code that uses UniqueTable. Any attempt to set UniqueTable results in the error message:
You entered an expression that has an invalid reference to the property UniqueTable
The following code works on Access 2010 but encounters above error on Access 2013 when attempting to set UniqueTable:
dim conn AS New ADODB.Connection
conn.ConnectionString = "DATA PROVIDER=SQLOLEDB;DATA SOURCE=server1;DATABASE=database1;Integrated Security=SSPI;"
conn.CursorLocation = adUseServer
conn.Provider = "MSDataShape"
conn.Open
Dim cmd As New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT TOP 10 * FROM Members WHERE MemberID IS NOT NULL"
cmd.Execute
Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenKeyset, adLockOptimistic
Set Recordset = rs
UniqueTable = "Members"
While searching for a solution I have found only a couple of other cases where this error has been mentioned, and no solutions so far.
I'm afraid that you may be out of luck on this one. I was able to recreate your issue: code that successfully set a form's UniqueTable property in Access 2010 failed in Access 2013 with the same runtime error message.
A Google search for microsoft access uniquetable yields a number hits, and the vast majority of them refer to the use of that form property in an ADP. ADP support was completely removed from Access 2013, so my guess is that UniqueTable support was removed along with it. (The IntelliSense feature within the Access 2013 VBA editor still offers Me.UniqueTable as a property of a Form object, but Access 2013 apparently does not allow us to set a value for it at runtime.)
You can set Recordset.Properties("Unique Table"), e.g.:
rs.Properties("Unique Table") = "members"
see ADO Dynamic Properties
You can still use Me.UniqueTable to make sure your select join into a ADO recordset is working while delete data from many-table. Also me.ResyncCommand is working from VBA code, not any more as a property in form design, but behind the form in the code like Form Load.
I am opening Lotus files to get data from them. How do I instantiate the Lotus application without using GetObject? I have a reference to "Lotus 123". I am using Lotus SmartSuite 97.
This code works OK but it seeems I should be able to instantiate the Lotus application directly instead of using GetObject.
'get LotusWin
Dim LotusApp As Lotus123.Application
Dim wb As Lotus123.Document
Set wb = GetObject("C:\Temp\TestCopy.WK3", "Lotus123.Workbook")
Set LotusApp = wb.Application
LotusApp.Visible = True
wb.Activate
I tried to use Dim LotusApp As New Lotus123.Application but it give a compile error: Invalid use of New keyword.
I tried to use Dim LotusApp As New Lotus123 but it give a compile error: Expected user-defined type, not project.
I am using Excel VBA as my platform to run the code, but this is not an Excel question so please don't suggest adding an Excel tag.
Also I'm not interested in converting files to Excel.
How do I instantiate the Lotus application without using GetObject?
GetObject() returns a reference to an object provided by a COM component, in your case Lotus123.
As you are communicating with Lotus123 via COM, and Lotus123 apparently does not support the "As New" syntax (which wasn't properly supported even in VB6, and Lotus123 is way older) I see no alternative to using GetObject().
I have a vb windows application with 2 forms, where form2 is called from form1 using
form2.showdialog()
I added a web browser control to form2, and I'm getting the following error at the point where form2 is called:
Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
I tried:
1) adding STAThread() to the form_load()
2) I added a module to my application, and created a sub main(), with the STAThread attribute applied to it
3) I marked the sub startup() with STAThread()
And none of this helped.
Any tips on how to get around this issue?
Thanks,
rcpg
If you use the form project template and did not change anything in project settings you don't have control over the main function - the compiler will generate one that has STAThread for you.
Are you creating some objects (such as Timer) in the form whose type has a SynchronizingObject property and you forgot to assign a synchronizing object to it?