Solved

Conflict with Declare Function and WithEvents Function

Posted on 2003-11-01
3
779 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

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 70

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

738 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