Solved

Conflict with Declare Function and WithEvents Function

Posted on 2003-11-01
3
751 Views
Last Modified: 2013-12-25
I have a Declare Function (Below)that will automatically determine the usersname that is logged in and insert it into a field. And it works great up until I add the (Private WithEvents poSendMail As vbSendMail.clsSendMail
Dim TicketID As Longfunction) (Needed in order for my e-mail to work)
Each time I try and run my app adding both at the same time I get an error message :Compile error : Invalid Attribute in sub or function and WithEvents poSendMail As vbSendMail.clsSendMail gets highlighted.... However, if I remove the Declare Function it works again, but the email doesn't.... Any help would be appreciated. Using VS6 SP5, Win2K and Access2k ADO

(Declare Code)
Private Declare Function GetUserNameA Lib "advapi32.dll" _
    ( _
    ByVal lpbuffer As String, _
    nSize As Long _
    ) As Long
    Private Function GetUserName() As String
    Dim strName As String * 255
    GetUserNameA strName, 255
    GetUserName = Left$(strName, InStr(strName, Chr(0)) - 1)
End Function

(VBSendMail Code)
Private WithEvents poSendMail As vbSendMail.clsSendMail
0
Comment
Question by:just3082
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 9665773
You normally declared all your variables at the top and then write your procedures. Try this sequence:


Private Declare Function GetUserNameA Lib "advapi32.dll" _
    ( _
    ByVal lpbuffer As String, _
    nSize As Long _
    ) As Long

Private WithEvents poSendMail As vbSendMail.clsSendMail

Private Function GetUserName() As String
    Dim strName As String * 255
    GetUserNameA strName, 255
    GetUserName = Left$(strName, InStr(strName, Chr(0)) - 1)
End Function


0
 

Author Comment

by:just3082
ID: 9666516
Thanks,
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9666537
If it is working, you need to close the question by accepting one of the comment!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now