Solved

Declaring an API function in VB

Posted on 1998-11-10
1
230 Views
Last Modified: 2010-04-30
I've been trying to declare an API function, but keep getting an error. I've added the declaration statement inside the command1-click sub procedure, but get the following error; Compile error: Only comments may appear after End Sub, End Function,  or End Property.
I tried moving the declaration statement to "General Declarations" but get the following error; Compile error: constants, fexed-length strings, arrays... not allowed as public members of object models.
I've used the exact declaration statement out of the book I'm using.
Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Can anybody tell me why I'm getting the errors, am i trying to declare in the incorrect place???
Thanks for any info anybody can provide.
0
Comment
Question by:darrel
1 Comment
 
LVL 13

Accepted Solution

by:
Mirkwood earned 200 total points
ID: 1444055
Put the declaration to the top of your modul or form.
Incase of a form or class put the word private in front of it.
private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

947 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

19 Experts available now in Live!

Get 1:1 Help Now