Declaring an API function in VB

Posted on 1998-11-10
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.
Question by:darrel
1 Comment
LVL 13

Accepted Solution

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Updates not working for MS Windows 7 12 181
VB6 Compile Compatibility Issue 4 115
Excel Automation VBA 19 88
VB6 - Cannot type when doing an extract from MSHFlexgrid to Excel 6 18
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 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