Variable defined as Public on a standard module, is not recognized (2 Viewers)

amorosik

Active member
Local time
Today, 20:31
Joined
Apr 18, 2020
Messages
608
I have a project created with Access 2013, 32-bit
I normally use this procedure to export the entire project to a text file and archive it (VCS_ImportExport.bas / ExportAllSource)
After the last export, I also followed the reverse procedure, and then tried recreating the project from the newly exported text files (VCS_ImportExport.bas / ImportProject)

The import was successful, and I was able to compact the created file
However, when I try to compile it, it seems not to recognize variables in some standard modules that are actually present and defined "Public gbDebug As Boolean" in the standard module modVariabiliGlobali.

I have checked the presence of the variable in the modVariabiliGlobali module several times, and it is indeed present
But within other modules (at the beginning of each standard module there is Option Explicit), it is not recognized.
I also tried defining it as Global, but there was no difference.

If I delete the Option Explicit line at the beginning of the module modFtpServer using the variable, then control passes and compilation continues.

Note that this procedure for exporting and completely rebuilding an Access project is something I've been doing the same way for several years, and this is the first time it didn't restart on the first try.

The question is: why is the gbDebug variable used in the modFtpServer standard module not recognized? (error: Variable not defined)
 
you only need to define all public variables in one module or only one declaration of each public variables.
 
This is what I did.
All global variables are defined within the standard modVariabiliGLobali module and are in the form "Public gbDebug As Boolean"
But if I try to use gbDebug in other forms/modules/report/class, the code doesn't seem to recognize them.
(All modules have the Option Explicit line)
 
If I delete the Option Explicit line at the beginning of the module modFtpServer using the variable, then control passes and compilation continues.

It will run because the point of Option Explicit is it checks for undeclared variables.
You've stored them in a standard module right? Not in a Form module or class module.
Declared in the header & not between procedures...
 
Yes, on a standard module
On modVariabiliGlobali threre are only variables, no procedures, no functions
 
Sorry I see you put that. Ok you said a Compact & Repair worked fine & it decompiles without problem (excluding "Public gbDebug As Boolean" in the standard module modVariabiliGlobali.

For the crack create a new blank db & import everything Ribbon > External Data, New Data Source > From Database > From Access, select all Access Database Object Types; Tables, Queries, Reports... EVERYTHING.

Compile & see if that brings any joy forcing a rebuild.

1756117562890.png


EDIT - check if Option Compare statement is in the modules where the var is not recognized. If it is comment it out temporarily or check your casing on the var.

Could try this which is not the issue but may force some kind of rebuild in the background of some kind.
 
Last edited:
Thanks for the suggestion
But I just tried importing all the objects from a text files, and the first time I try to compile it, it gives me the problem of undefined variables
I absolutely have to continue using the project as before, before exporting/importing, otherwise it won't work properly
But I don't understand the nature of the problem, and especially why it's appearing now, given that I've already performed the same procedure many times and everything has always worked correctly
The last time I did it was about a month ago without any problems.
 
Last edited:
But I just tried importing all the objects from a text file, and the first time I try to compile it, it gives me the problem of undefined variables
"The first time" means if you try to compile the created database file a second time it works?
Or do you mean if worked for months and now it fails for the first time?

Do you import into a newly created blank Access file or do you import into a file already existing for some time?
I think, the only explanation for the problem you are seeing is that the Access file itself suffers a problem; either corruption of the file or maybe a problem with missing references.
 
"First time" indicates the first time I try compile after the project has been imported from text files

"..Do you import into a newly created blank Access file .." Yes
 
Reading through this, I can see how you are puzzled. Defining a public variable in a standard module is something I have done many times.

I am not entirely clear on your description of how you export the whole project, but I'm more interested in something else, very narrow and specific.

Can you manually export that standard module to text from the VBA window? I.e. export the one module that contains your public variables. Then open the resultant text file with Notepad. Can you see the text of the public declaration of that variable? Not talking about when you reimport and recompile, but when the module is sitting as a flat text file. Do you see any extraneous characters?
 
I exported manually by going over the module and right-clicking, then selecting Export to Text File
The result is shown below
At first glance, it doesn't seem like anything special.


Code:
Attribute VB_Name = "modVariabiliGlobali"
Option Compare Database
Option Explicit

'Public sFiles() As String
Public RsAdodb As New ADODB.Recordset

Public dsn_in_uso As Long
Public nome_database_dsn_in_uso As String

Public dummy As Variant, dummy2 As Variant
Public gbDebug As Boolean

Public tip_con As String
Public pos_o_ope As String

Public form_provenienza As String
Public controllo_provenienza As String
Public flag_aggiorna_controllo_provenienza As Long
Public valore_controllo_provenienza As Long
Public documenti_selezione_anagrafica_form_originale As String

' Vendita Al banco - Richiedi Sconto
Public sconto_richiesto As Currency
Public codice_pagamento_richiesto As Long
Public importo_versato_richiesto As Currency
Public resto_cliente_richiesto As Currency

Public flag_descrizione_richiesta As Boolean
Public flag_quantita_richiesta As Boolean
Public flag_prezzo_unitario_richiesto As Boolean
Public flag_reparto_richiesto As Boolean
Public flag_codice_interno_richiesto As Boolean

Public flag_richiedi_sconto_descrizione_pagamento As Boolean

Public avvio_ip_address         As String
Public avvio_username_erp2      As String
Public avvio_password_erp2      As String
Public avvio_username_windows   As String
Public avvio_versione_programma As String
Public avvio_computer_name      As String

Public id_mastro_attuale As Long
Public id_conto_attuale As Long
Public id_sottoconto_attuale As Long
 
Public codice_articolo_attuale As String
Public id_anagrafica_attuale As Long

Public movimenti_contabili_controllo_richiedente As String

Public codice_componente_attuale As String
Public descrizione_componente_attuale As String
Public codice_articolo_figlio_attuale As String
Public acquisti_codice_interno_attuale As String

Public Const vbKeyTastierinoPiu = 107
Public Const vbKeyTastierinoMeno = 109
Public Const vbKeyTastierinoAsterisco = 106
Public Const vbKeyTastierinoBackSpace = 144
Public Const vbKeyTastierinoBackSlash = 144

Public codice_registro_attuale          As Long
Public flag_aggiorna_tabella            As String

Public incassi_da_aggiornare_campo      As String
Public incassi_da_aggiornare_valore     As Currency
Public incassi_da_aggiornare_data       As String

Public password_corrente As String

Public id_mem_fin                       As Long
Public data_chiusura_rich               As String
Public ora_chiusura_rich                As String
Public codice_registro_rich             As Long
Public chk_flag_fine_anno               As Long

Public codice_interno_attuale               As String
Public codice_articolo_fornitore_attuale    As String
Public descrizione_attuale                  As String
Public PREZZO_ATTUALE                       As Currency
Public sconto_attuale                       As Currency
Public codice_reparto_attuale               As Long

Public GESTIONEDOCUMENTALE_TABELLA_ATTUALE          As String
Public GESTIONEDOCUMENTALE_CAMPO_ID_TABELLA_ATTUALE As String
Public GESTIONEDOCUMENTALE_ID_TABELLA_ATTUALE       As Long

Public id_documentitestate_saldaconto_selezionato As Long
Public id_movimenticontabilitestate_saldaconto_selezionato As Long
Public id_documentitestatedatipag_saldaconto_selezionato As Long

Public tipifile_attuale_codice As Long
Public tipifile_attuale_descrizione As String
Public codice_estensione_attuale As Long

Public dir_exe As String
Public dir_mdb As String
Public dir_bak As String
Public dir_tmp As String
Public dir_hlp As String
Public dir_mov As String
Public dir_rpt As String
Public dir_ute As String
Public dir_azi As String

Public codice_gruppo_attuale        As Long
Public utente_attuale_nome          As String
Public utente_attuale_codice        As Long

Public report_filename              As String
Public report_destinazione          As Integer
Public report_email_destinatario    As String
Public report_email_oggetto         As String
Public report_email_messaggio       As String
Public report_numero_copie          As Long
Public report_da_pagina             As Long
Public report_a_pagina              As Long
Public report_print_filename        As String
Public report_nome_stampante        As String

Public stampante_letta_in_avvio As String

Public errore_codice            As String
Public errore_descrizione       As String
Public errore_posizione         As String

Public MyRsAdoTemp As ADODB.Recordset

Public Type db_ado
    numero_lettura As Integer
    NOME_TABELLA As String
    numero_campi As Integer
    numero_record As Integer
    tipo As String
    size As Integer
    scale As Integer
    not_null As Integer
    End Type
  
Public MyTempVar As db_ado

Public ID_ANAGRAFICHENATANTILICENZE_attuale As Long
Public id_movimentidimagazzino_corrente     As Long
Public id_prezzi_attuale As Long
Public id_marchiimmagini_attuale As Long
Public id_articolo_alternativo_attuale As Long
Public id_venditealbancotestate_attuale As Long
Public id_inventario_testata_attuale As Long
Public id_inventario_riga_attuale   As Long
Public id_fericevute_attuale As Long

Public descrizione_articolo_attuale As String

Public codice_deposito_attuale As Long
Public codice_listino_attuale As Long
Public codice_valuta_attuale As Long

Public righe_documento_create As Long
Public tempo_iniziale As Variant

Public flag_aggiorna_griglia_articoli_acquisti As Long
Public flag_aggiorna_anagrafica As Long
Public flag_aggiorna_anagrafica_da_articoli As Long
Public flag_aggiorna_lista_cerca_articoli As Long
Public flag_aggiorna_articoli As Long
Public flag_aggiorna_banca As Long
Public flag_prezzo As Long
Public flag_rinfresca_recordset As Long
Public flag_magazzino_editabile As Long
Public flag_selezione_stampante As Long
Public flag_aggiorna_documenti_tipi As Long
Public flag_aggiorna_linee_numerazioni As Long
Public flag_aggiorna_causali_magazzino As Long

Public stringa_sql_attuale As String

Public dtaARTICOLI_curwhere As String
Public dtaARTICOLI_cursort As String

Public id_documentirighe_attuale As Long
Public ID_ANAGRAFICHE_attuale As Long
Public ID_DOCUMENTITESTATE_attuale As Long
Public ID_DOCUMENTITESTATE_acquisto_attuale As Long
Public ID_DOCUMENTIRIGHE_acquisto_attuale As Long
Public id_movimentocontabiletestata_attuale As Long
Public id_prezzo_attuale As Long
Public id_movimenticontabilitestate_attuale As Long

Public codice_cliente_attuale As Long
Public codice_cliente_attuale_da_articoli As Long
Public codice_banca_attuale As Long
Public codice_marchio_attuale As Long

Public esportazione_documenti_cur_where As String

Public dtaARTICOLIoperazioniGlobali_curwhere As String
Public dtaARTICOLIoperazioniGlobali_cursort  As String

Public dtaANAGRAFICHE_curselect As String
Public dtaANAGRAFICHE_curfrom As String
Public dtaANAGRAFICHE_curwhere As String
Public dtaANAGRAFICHE_cursort As String

Public dtaRIGHE_curselect As String
Public dtaRIGHE_curfrom As String
Public dtaRIGHE_curwhere As String
Public dtaRIGHE_cursort As String

Public dtaVisualizzaArticoli_cursort As String
Public dtaVisualizzaArticoli_curwhere As String

Public curselect_attuale As String
Public curfrom_attuale   As String
Public curwhere_attuale  As String
Public cursort_attuale   As String

Public rptDDT_curwhere As String
 
Last edited:
Double check that youhaven't also defined gbDebug in another module (as Private or Public)
Duplicate declarations can cause problems.
 
After you re-import your modules. In your code that references these variables what happens when you type
"modVariabiliGlobali. "

Does intellisense show all the variables you would expect?
mod.PNG

I exported this module. Deleted it and re-imported it. It compiled with no issue.
My guess you have a similar or duplicate module and that is the thing causing the error and not this module.

I would import one module at a time (or a few) and compile. See where the compilation fails.
 
Last edited:
IMO, exposing a list of globals like that in a standard module is a very serious design flaw. Like, who produces data for each of those, and who are the consumers? It's like a crime scene. Nothing can be known for certain, and everyone, to be ruled out as a suspect, has to be tirelessly investigated.
 
Double check that youhaven't also defined gbDebug in another module (as Private or Public)
Duplicate declarations can cause problems.

Checked
But gbDebug (like other public vars) is defined only on modVariabiliGlobali
 
After you re-import your modules. In your code that references these variables what happens when you type
"modVariabiliGlobali. "

Does intellisense show all the variables you would expect?
View attachment 121274
I exported this module. Deleted it and re-imported it. It compiled with no issue.
My guess you have a similar or duplicate module and that is the thing causing the error and not this module.

I would import one module at a time (or a few) and compile. See where the compilation fails.

Good question
Yes, on other modules, for example modFtpServer module, the intellisense show all vars expected

Wait a moment, if i write modVariabiliGlobali.gbDebug the variable is correctly recognized, if i write gbDebug si not recognized
As if gbDebug was a public member of a class module, but modGlobalVariables is a standard module
 
Last edited:
IMO, exposing a list of globals like that in a standard module is a very serious design flaw. Like, who produces data for each of those, and who are the consumers? It's like a crime scene. Nothing can be known for certain, and everyone, to be ruled out as a suspect, has to be tirelessly investigated.

"...a list of globals like that..."
Exactly, what list of global variables wouldn't be a very serious design flaw?
 
Copied the contents of modVariabiliGlobali to a text file
Deleted the modVariabiliGlobali module
Compacted the project
Created a new module, named modVariabiliGlobali2
Pasted the contents of the text file into the new module
Now debug/compile correctly
Access probably somehow 'marked' the module as a 'class module' during the import
The really strange thing is that the same code is used both for exporting from an Access project to individual text files and for importing from individual text files to an Access project. I've been using it for several years and it's always the same.
And this is really worrying because if it messed up one module, it could have messed up others as well
 

Users who are viewing this thread

Back
Top Bottom