P
Piotr
Hi, I have following sub its work fine when I run it from VBA editor,
but when I try to automate it and I run it from macro I get VBA editor
open window without even a message ?
Does anyone know what is wrong ?
Sub razem()
Dim tbl As TableDef
Dim strdir As String
Dim strfiles As String
Dim strimportfiles As String
Dim sql As String
Dim table As String
Dim sqlq As String
table = "TRA"
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 3) = table Then CurrentDb.Execute "DROP TABLE " &
tbl.Name '<---VBE highlites this line
Next
table = "GZT"
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 3) = table Then CurrentDb.Execute "DROP TABLE " &
tbl.Name '<---VBE highlites this line
Next
intteller = 0
strdir = "R:\bazy_lok\fk2005"
strfiles = strdir + "\TRA*.dbf"
strimportfiles = Dir$(strfiles)
Do Until strimportfiles = ""
DoCmd.TransferDatabase acImport, "dBase IV", strdir, acTable,
strimportfiles, "TRA", False
strimportfiles = Dir$()
intteller = intteller
Loop
intteller = 0
strdir = "R:\bazy_lok\fk2005"
strfiles = strdir + "\GZT*.dbf"
strimportfiles = Dir$(strfiles)
Do Until strimportfiles = ""
DoCmd.TransferDatabase acImport, "dBase IV", strdir, acTable,
strimportfiles, "GZT", False
strimportfiles = Dir$()
intteller = intteller
Loop
table = "TRA"
For Each tbl In CurrentDb.TableDefs
sqlq = "INSERT INTO TR_RAZEM SELECT * FROM " & tbl.Name
If Left(tbl.Name, 3) = table Then CurrentDb.Execute sqlq '<---VBE
highlites this line"
Next
table = "GZT"
For Each tbl In CurrentDb.TableDefs
sqlq = "INSERT INTO GZ_RAZEM SELECT * FROM " & tbl.Name
If Left(tbl.Name, 3) = table Then CurrentDb.Execute sqlq '<---VBE
highlites this line"
Next
End Sub
but when I try to automate it and I run it from macro I get VBA editor
open window without even a message ?
Does anyone know what is wrong ?
Sub razem()
Dim tbl As TableDef
Dim strdir As String
Dim strfiles As String
Dim strimportfiles As String
Dim sql As String
Dim table As String
Dim sqlq As String
table = "TRA"
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 3) = table Then CurrentDb.Execute "DROP TABLE " &
tbl.Name '<---VBE highlites this line
Next
table = "GZT"
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 3) = table Then CurrentDb.Execute "DROP TABLE " &
tbl.Name '<---VBE highlites this line
Next
intteller = 0
strdir = "R:\bazy_lok\fk2005"
strfiles = strdir + "\TRA*.dbf"
strimportfiles = Dir$(strfiles)
Do Until strimportfiles = ""
DoCmd.TransferDatabase acImport, "dBase IV", strdir, acTable,
strimportfiles, "TRA", False
strimportfiles = Dir$()
intteller = intteller
Loop
intteller = 0
strdir = "R:\bazy_lok\fk2005"
strfiles = strdir + "\GZT*.dbf"
strimportfiles = Dir$(strfiles)
Do Until strimportfiles = ""
DoCmd.TransferDatabase acImport, "dBase IV", strdir, acTable,
strimportfiles, "GZT", False
strimportfiles = Dir$()
intteller = intteller
Loop
table = "TRA"
For Each tbl In CurrentDb.TableDefs
sqlq = "INSERT INTO TR_RAZEM SELECT * FROM " & tbl.Name
If Left(tbl.Name, 3) = table Then CurrentDb.Execute sqlq '<---VBE
highlites this line"
Next
table = "GZT"
For Each tbl In CurrentDb.TableDefs
sqlq = "INSERT INTO GZ_RAZEM SELECT * FROM " & tbl.Name
If Left(tbl.Name, 3) = table Then CurrentDb.Execute sqlq '<---VBE
highlites this line"
Next
End Sub