Solved

Declaring an API function in VB

Posted on 1998-11-10
1
234 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

809 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