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.

Thanks

CODE

Private Sub cbCancel_Click() If Ftp1.State = tcpConnected Then If bRetrieving Then Ftp1.Abort End If Ftp1.Logout End If If Timer1.Enabled = True Then Timecount = 99 Else FTPrc = 8 Unload Me End IfEnd Sub

Here's some more of the code. Same for one that works and one that doesn't.

CODE

Option ExplicitDim gAppName As StringDim gHost As StringDim gUser As StringDim gPass As StringDim gRemoteFileName As StringDim gLocalFileName As StringDim bRetrieving As BooleanDim Timecount As Integer

Private Sub cbCancel_Click() If Ftp1.State = tcpConnected Then If bRetrieving Then Ftp1.Abort End If Ftp1.Logout End If If Timer1.Enabled = True Then Timecount = 99 Else FTPrc = 8 Unload Me End IfEnd Sub

How many standard or class modules do you have in each file? Are you sure they're all the same in both files? If not, then search for all instances of FTP1 in the working file and see if you have the same exact ones in the non-working file.

It's possible the variable was declared with a global scope in the working version.

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:

ClassModuleName.PropertyOrMethod.

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:

CODE

Option Compare DatabaseOption 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.

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.