Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Conflict with Declare Function and WithEvents Function

Posted on 2003-11-01
3
Medium Priority
?
805 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 70

Accepted Solution

by:
Éric Moreau earned 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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