L'importazione la faccio cosi:
In questo modo importo una tabella xls esterna e faccio la comparazione dei suoi campi con la mia Table1 (che è quella che contiene i campi giusti).codice:Public Function impTable() Dim f As Object Dim strFile As String Dim strFolder As String Dim varItem As Variant Set f = Application.FileDialog(3) f.AllowMultiSelect = False If f.Show Then For Each varItem In f.SelectedItems strFile = Dir(varItem) strFolder = Left(varItem, Len(varItem) - Len(strFile)) DoCmd.DeleteObject acTable, "CompareTable1" ' Import data from Excel using a static range DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel12, "CompareTable1", strFolder & strFile, True, "A1:Z1" checkTable Next End If Set f = Nothing End Function Public Function checkTable() Dim db As DAO.Database Dim tbl1 As DAO.TableDef Dim tbl2 As DAO.TableDef Dim intLoop As Integer Dim strMessage As String Set db = CurrentDb Set tbl1 = db.TableDefs("Table1") Set tbl2 = db.TableDefs("CompareTable1") If tbl1.Fields.Count = tbl2.Fields.Count Then MsgBox "ok" Else strMessage = tbl1.Name & " has " & tbl1.Fields.Count & " fields, while " & _ tbl2.Name & " has " & tbl2.Fields.Count & " fields." & vbCrLf End If If tbl1.Fields.Count > tbl2.Fields.Count Then action1 End If If tbl1.Fields.Count < tbl2.Fields.Count Then action2 End If If tbl1.Fields.Count = tbl2.Fields.Count Then action3 End If Set tbl2 = Nothing Set tbl1 = Nothing Set db = Nothing End Function
Quello che devo ottenere è una funzione che mi dica se la tabella xls esterna è identica alla mia Table1 come struttura (nome e numero di campi).
A seconda del risultato eseguo un'azione.
Credo sia un metodo piuttosto macchinoso e mi obbliga ad importare la tabella, mentre io vorrei qualcosa di piu snello che mi consenta di controllare i campi da fuori senza importare.
E' possibile?


Rispondi quotando