Solved

Conflict with Declare Function and WithEvents Function

Posted on 2003-11-01
3
763 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 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

773 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