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
Solved

Conflict with Declare Function and WithEvents Function

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
vb6 connector to SQL Server 2 37
Advice in Xamarin 21 96
pop out of webbrowser1 control vba6 5 25
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

856 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