Newsgroup: it.comp.lang.visual-basic
Titolo: ACCESS97 VBA Function gira solo su alcuni PC

AIUTO
Ho un problema in ACCESS97, ho un programma Access che usa una
function (GetMDBNAme() )da me creata del tipo: apri una finestra che
mostra le directory e i files....dove scegliere un file che viene
caricato nel database principale e reso corrente.
questa function gira solo su alcuni pc con access e non su altri
(Access97 è su tutti in italiano). PERCHE'?
in pratica la finestra non si apre e viene mostrato il messaggio della
function che dice "User pressed cancel" perchè ovviamente non è stato
selezionato un input da associare alla variabile FILENAME che riamne
vuota e quindi il check IF.....restituisce il warning suddetto.
1 milione di € a chi mi risponde.....€€€€€€€€€€€€ grazie
Private Sub Data_File_Click()
    '  Update connection information in attached tables.    
    Const MAXTABLES = 11  'Number of attached tables for
progressmeter.
famigli...@tin.it
    Const NONEXISTENT_TABLE = 3011
    Const ACCESS_DENIED = 3051    Const READ_ONLY_DATABASE = 3027    
    Dim TableCount As Integer
    Dim filename As String, SearchPath As String, Temp As String
    Dim ReturnValue As Variant, AccDir As String, I As Integer
    Dim MyTable As TableDef    Dim MyDB As Database, MyRecords As
Recordset
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    '  Initialize progress meter.
    ReturnValue = SysCmd(SYSCMD_INITMETER, "Attaching
Tables",MAXTABLES)
    On Error Resume Next
'THIS IS THE TROUBLE'THIS IS THE TROUBLE
'QUESTO E' IL CASINO    
 
   filename = GetMDBName()             ' Display Open File dialog.
    filename = Trim(filename)
    If filename = "" Then GoTo Exit_Failed ' User pressed Cancel.
    If InStr(1, filename, "SILCLASS.mdb", 1) Then GoTo Exit_Wrong_file
' User selected *SILCLASS MAIN PROGRAM.MDB.    ' Loop through all
tables.
    TableCount = 1  ' Initialize TableCount for status meter.
    For I = 0 To MyDB.TableDefs.Count - 1        Set MyTable =
MyDB.TableDefs(I)
        If MyTable.Connect <> "" Then
            MyTable.Connect = ";DATABASE=" & filename            Err =
0
            MyTable.RefreshLink'   MsgBox "TableDefNo - " & I, 16,
"Test"
            If Err <> 0 Then               If Err = NONEXISTENT_TABLE
Then
                  MsgBox "File '" & filename & "' does not contain
required table '" & MyTable.SourceTableName & "'!", 16, "Can't Run
*SILCLASS MAIN PROGRAM"               ElseIf Err = ACCESS_DENIED Then
                  MsgBox "Couldn't open '" & filename & "' because it
is read-only or it is located on a read-only share.", 16, "Can't Run
*SILCLASS MAIN PROGRAM"               ElseIf Err = READ_ONLY_DATABASE
Then
                  MsgBox "Can't reattach tables because '*SILCLASS
MAIN PROGRAM.MDB' is read-only or is located on a read-only share.",
16, "Can't Run *SILCLASS MAIN PROGRAM"               Else
                  MsgBox Error, 16, "Can't Run *SILCLASS MAIN PROGRAM"
               End If               GoTo Exit_Final            End If
            TableCount = TableCount + 1
            ReturnValue = SysCmd(SYSCMD_UPDATEMETER, TableCount)      
 End If
    Next I    Me![Classification].Enabled = True
    Me![Reporting].Enabled = True    Me![Miscellaneous].Enabled = True
    Me![Diagnostics].Enabled = True    Me![Units].Enabled = True
    Me![Drawings].Enabled = True    Me![TagTypes].Enabled = True
    Me![Tags].Enabled = True    Me![Keywords].Enabled = True
    Me![Exit].Enabled = True    Me![Project].Enabled = True
    Me.Caption = "SILCLASS program v 1.b "
&Mid(MyDB.TableDefs(8).Connect, 11)
    GoTo Exit_FinalExit_Failed:
    MsgBox "You pressed Cancel!", 16, "Can't Attach"    GoTo
Exit_Final
Exit_Wrong_file:
    MsgBox "You have selected '*SILCLASS MAIN PROGRAM.MDB'! Select a
datafile.", 16, "Can't Attach"Exit_Final:
    ReturnValue = SysCmd(SYSCMD_REMOVEMETER)Exit_Data_File_Click:   
Exit Sub
Err_Data_File_Click:    MsgBox Error$    Resume Exit_Data_File_Click  
 End Sub
' THIS IS THE FUNCTION NOT EXECUTED' THIS IS THE FUNCTION NOT EXECUTED
' THIS IS THE FUNCTION NOT EXECUTEDPrivate Function GetMDBName() As
String
    '  Datafile chosen by user in OpenFile dialog box.
    '  (This function works in conjunction with GetMDBName2
andStringFromSz to
    '  display a File-Open dialog that prompts user for datafile.
    '  It uses code found in WZLIB.MDA.)
    '  It is taken over from SOLUTIONS.MDB    Const OFN_SHAREAWARE =
&H4000
    Const OFN_PATHMUSTEXIST = &H800    Const OFN_HIDEREADONLY = &H4
    Dim OFN As WLIB_GETFILENAMEINFO
    '  Fill ofn structure which is passed to wlib_GetFileName
    OFN.hwndOwner = 0    OFN.szFilter = "Databases
(*.mdb)|*.mdb|All(*.*)|*.*||"
    OFN.nFilterIndex = 1    OFN.szTITLE = "Choose a datafile! "
    OFN.Flags = OFN_SHAREAWARE Or OFN_PATHMUSTEXIST OrOFN_HIDEREADONLY
    OFN.szDefExt = "mdb"
    '  Call wlib_GetFileName function and interpret results.
    If (GetMDBName2(OFN, True) = False) Then
        GetMDBName = StringFromSz(OFN.szFile)    Else       
GetMDBName = ""
    End IfEnd Function
Private Function GetMDBName2(gfni As WLIB_GETFILENAMEINFO, ByVal fOpen
As Integer) As Long    '  This function acts as a cover to
MSAU_GetFileName in
MSAU200.DLL.
    '  wlib_GetFileName terminates all strings in gfni structure
withnulls and
    '  then calls DLL version of function.  Upon returning
fromMSAU200.DLL, null
    '  characters are removed from strings in gfni.        Dim lRet As
Long
    gfni.szFilter = RTrim$(gfni.szFilter) & Chr$(0)
    gfni.szCustomFilter = RTrim$(gfni.szCustomFilter) & Chr$(0)
    gfni.szFile = RTrim$(gfni.szFile) & Chr$(0)
    gfni.szFileTitle = RTrim$(gfni.szFileTitle) & Chr$(0)
    gfni.szInitialDir = RTrim$(gfni.szInitialDir) & Chr$(0)
    gfni.szTITLE = RTrim$(gfni.szTITLE) & Chr$(0)
    gfni.szDefExt = RTrim$(gfni.szDefExt) & Chr$(0)
    lRet = wlib_MSAU_GetFileName(gfni, fOpen)
    gfni.szFilter = StringFromSz(gfni.szFilter)
    gfni.szCustomFilter = StringFromSz(gfni.szCustomFilter)
    gfni.szFile = StringFromSz(gfni.szFile)
    gfni.szFileTitle = StringFromSz(gfni.szFileTitle)
    gfni.szInitialDir = StringFromSz(gfni.szInitialDir)
    gfni.szTITLE = StringFromSz(gfni.szTITLE)
    gfni.szDefExt = StringFromSz(gfni.szDefExt)    GetMDBName2 = lRet
End Function

 AIUTO
Vogliamo supporre che OFN sia un commondialog - che non è installato su
alcuni pc - ???
ciao
ugo