X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
> Compile Error - Variable Not Defined    
post Oct 12 2018, 02:15 PM

Posts: 197
Joined: 16-August 12

Hi. I have a piece of code that is giving a compile error. The message says it's not defined but the odd thing is I have a different project with similar code and the same variable (FTP1) that is not defined either and it runs fine. Not sure what I'm missing. If I try to declare it, I'm not sure of the type. I inherited a bunch of VB6 project code that I'm trying to get to work similar to the one that does work. I can't just copy one to the other as there are some differences elsewhere.

This is part of a project that opens a user interface to import data into an Access database.

I get the error on the code below and it highlights Ftp1. Looking for ideas of where else to look.


Private Sub cbCancel_Click()
    If Ftp1.State = tcpConnected Then
        If bRetrieving Then
        End If
    End If
    If Timer1.Enabled = True Then
        Timecount = 99
        FTPrc = 8
        Unload Me
    End If
End Sub
Go to the top of the page
Start new topic
post Oct 12 2018, 07:23 PM

UtterAccess VIP
Posts: 3,132
Joined: 12-April 07
From: Edmonton, Alberta Canada

There are 3 possible choices.

In the past, you did not have option explicit, so the code compiled (however you HAVE confirmed this).

In the past you had some module with a GLOBAL instance of the class declared, and you are missing that code and declare.
(This is possible, but if you sure this is NOT the case?

Well, then all that is left here is THIS case, and I am betting this is your issue:

In Access 97 (and before), it was possible to use a class module WITHOUT declaring an instance of that class.

And for reasons of compatibility and code not breaking?

Well, for VBA they wanted to adopt the correct object approach and concept that you have to create an instance of a class before you use it. However, lots of code would break!!!

So they added a hidden attribute to VBA code modules that controls this option.

If you “import” the code module from an older application, (say access 97), then that attribute will ALSO move along for the ride. (Actually, I think you have to upgrade????).

This means, that code could have moved from 97 to 2000, then 2003 and so on for a very long time.

Now, if you say do a cut + paste of code or use some kind of import that does NOT copy that special settings, then your code will now NOT compile were as before it would.

So, after access 97, if you create a class module, then you cannot just use:


And above is exactly what you have.

Two solutions:

In a standard code module (not class), simply declare a instance of the object.

So in some module, do this:

Option Compare Database
Option Explicit

Public Ftp1 As New Ftp1

Now read this next sentence VERY careful:

If the name of Ftp1 is NOT the same as the class name, then this bug or issue I am speaking of does NOT apply to you. (re-read this sentence until you are 100%, if not 200% crystal clear as to what I am telling you).

And if you for some reason do NOT want to do the above for a fix?

Fix #2: (again assuming this is your issue – and you read that above pargarigm 10 times – do NOT do the following if this is not your case).

Change the setting in VBA that allows you to directly use a class module without creating a instance of the module.

This will involve using the saveas text commad.

When you export your class to a text file, you see this setting:

Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False  
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False    <--- change to True!!!
Option Compare Database
Option Explicit

Dim m_FirstName      As String\

So for code in pre-access 2000, that above setting (VB_Creatble = True) is true.

For 2000 and after, the setting is as above (false).

I can’t quite recall the rules as to when the above attribute DOES follow. I believe if you use access to upgrade, the attribute setting is un-touched.

However, if you import, I think it is changed. So the feature is seemless for when you open the verison in a newer version of Access. But importing will break this.

Anyway, it been so long I don’t care much to worry as to “which” case cause this.

So a saveasText command from the immediate window, edit the above with a text editor (notepad), then delete your class, and re-mport the above with loadfromText.

The result will now that you can in VBA code use the class without declaring a instance of the class and your code will compile just fine.

However, I think the most easy approach is to simply declare the ftp1 public and NOT forget the “new” keyword.

It is a easy dead ringer to tell if this is the case if in fact the class module is also named ftp1.

If it is not, then you are simply missing the declare, and the declare as public suggestion will also fix this case. (and this information to change the setting will NOT work).

Albert D. Kallal (Access MVP, 2003-2017)
Edmonton, Alberta Canada
Go to the top of the page
post Oct 13 2018, 07:19 AM

UtterAccess Moderator
Posts: 13,121
Joined: 6-December 03
From: Telegraph Hill

@Albert, note that his is in VB6, not Access (aleadt I **think** so because of the forum!)


Can you confirm this is in VB6 please.

Do you have an FTP class module?

Looks like you're also missing a module instantiating the FTP class and also the Timer object too.



David Marten
Go to the top of the page
post Oct 13 2018, 08:07 AM

UtterAccess VIP
Posts: 3,132
Joined: 12-April 07
From: Edmonton, Alberta Canada


Thanks - this may well indeed be vb6 - but that also has this attribute setting!

(poster should clear up if this is VB6).

However, that same setting and feature is available in VB6 - I don't have VB6 installed on this machine as I type - and can't recall how you "display" those attributes.

What this means is that everything I stated would apply to VB6 (previous versions also allowed use of a class without creating a instance).
(the only difference is that save as text is not required).

So while the save-as text is not required, if the name of variable is the same name as the class module, then a good chance that this is/was still the issue.

I mean, I assume that the class ftp exists in the project.

Edit: as a fyi, the attribute setting is Attribute VB_PredeclaredId = True, not as per above.

Go to the top of the page
post Oct 13 2018, 02:11 PM

Posts: 197
Joined: 16-August 12

Thank you for all the replies. This is VB6.

This is the only module being used between the working version and non working and both have the same code.

Option Explicit
Global FTPrc As Integer
Public Data1 As Database
Public SupplierDBName As String
Public SourceFileName As String
Public LogFileName As String
Public sMyUserID As String
Public sDatahold(200) As String

Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long

Public Declare Function sendMessageByString& Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
     ByVal lParam As String)
Go to the top of the page
post Oct 13 2018, 04:01 PM

UtterAccess VIP
Posts: 3,132
Joined: 12-April 07
From: Edmonton, Alberta Canada

Well, there has to be a reference to ftp1.

It not clear I this is an ActiveX component that was dropped into the form, or that you have a class code module called ftp1.

Or you might have a reference to an external library.

So check the references in the older project.

If there is no class module called ftp1 or ftp in the old application, then it likely that the ftp1 is an ActiveX component that was dropped into that given form.

You can put your cursor on ftp1.State and hit shift-f2 to see what occurs (in the working application).

As this point, my best guess is thus that ftp1 is an ActiveX (ftp component) that was dropped into the form from the toolbox in the older application.

So check the references in the older application, it will show this external library.

Right now, so far, this is looking to be that a ActiveX FTP object was dragged onto the form that works in the older application.

Albert D. Kallal (Access MVP, 2003-2017)
Edmonton, Alberta Canada

Go to the top of the page
post Oct 15 2018, 07:11 AM

Posts: 197
Joined: 16-August 12


Making some headway. Got past the FTP1 error by referencing an active x component. Wasn't referenced in the working version so something is different between the two but still got the FTP form to come up and work. Now I'm getting "Database open error". The database is now a new version, .accdb vs. the old .mdb, and I changed the reference from Microsoft DAO 3.6 Object Library to Microsoft Office 16.0 Access database engine object. Perhaps that's not the correct reference?

This is the piece of code where I changed the database extension to the newer version.

ServerName = "\\cdtvnas13\Ops"
    dbname = "SUP3.[b]accdb[/b]"

Go to the top of the page

Posts in this topic

Custom Search

RSSSearch   Top   Lo-Fi    7th August 2020 - 01:37 PM