R
Roger
I have a situation where I have developed an Access application in which I
moved large datasets from an excel spreadsheet (I have several spanning over
an accounting period - 9-12 months).
The data comes in blocks of various sizes - so I can get the first block
with fields f1 to f12 or f1 to f20 and f1 to fn ( where n can be any whole
number).
The situation is this - I have written VBA code which loops through all the
blocks that I imported/pasted into the Access database and appends them to
one main table (via SQL code embedded in VBA code).
However as the blocks of data comes in various sizes the SQL code asks for a
field heading which doesn't exist in the particular block of data(e.g it
might search for field f10,but that block ranges from f1 to f9),the resulting
effect is that the SQL treats it as a Paramater query and asks for a suitable
entry.
My burning question is - How do I get rid of the dialog box (Paramater
query) which keeps popping up - I would like to run the code overnight but
that is difficult as I haven't found a way to get rid of the dialog box.
(Note:the workaround that I am using is to keep the "Enter key depressed"
with a solid object such as a stapler - but this leads to the code running
endlessly and leaves "huge " spaces in the VBA IDE ).
Any help out of my malaise will be gratefully appreciated.
Please refer to the generic code that I wrote :
'=====================================================
Function Import_Regulator
Dim obj As AccessObject, dbs As Object
Dim i As Integer
Dim x As Integer
Dim strB2U1 As String
Dim strB2U2 As String
Dim strB2U3 As String
Dim strB2U4 As String
Dim table1 As String
Dim table2 As String
Dim table3 As String
Dim table4 As String
Set dbs = Application.CurrentData
i = 0
x = 0
table1 = "ProuctTable1"
table2 = "ProuctTable2"
table3 = "ProuctTable3"
table4 = "ProuctTable4"
For i = 1 To 21
For Each obj In dbs.AllTables
strB2U1 = "INSERT INTO" & " " & "[" & table1
& "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )" _
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'ab*';"
strB2U2 = "INSERT INTO" & " " & "[" &
table2 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'xf*';"
strB2U3 = "INSERT INTO" & " " & "[" &
table3 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate" _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'qw*';"
strB2U4 = "INSERT INTO" & " " & "[" &
table4 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'up*';"
With DoCmd
.SetWarnings (False)
'
.RunSQL strB2U1
.RunSQL strB2U2
.RunSQL strB2U3
.RunSQL strB2U4
.SetWarnings (True)
End With
Next obj
Next i
End Function
'=====================================================
Regrds
Roger
moved large datasets from an excel spreadsheet (I have several spanning over
an accounting period - 9-12 months).
The data comes in blocks of various sizes - so I can get the first block
with fields f1 to f12 or f1 to f20 and f1 to fn ( where n can be any whole
number).
The situation is this - I have written VBA code which loops through all the
blocks that I imported/pasted into the Access database and appends them to
one main table (via SQL code embedded in VBA code).
However as the blocks of data comes in various sizes the SQL code asks for a
field heading which doesn't exist in the particular block of data(e.g it
might search for field f10,but that block ranges from f1 to f9),the resulting
effect is that the SQL treats it as a Paramater query and asks for a suitable
entry.
My burning question is - How do I get rid of the dialog box (Paramater
query) which keeps popping up - I would like to run the code overnight but
that is difficult as I haven't found a way to get rid of the dialog box.
(Note:the workaround that I am using is to keep the "Enter key depressed"
with a solid object such as a stapler - but this leads to the code running
endlessly and leaves "huge " spaces in the VBA IDE ).
Any help out of my malaise will be gratefully appreciated.
Please refer to the generic code that I wrote :
'=====================================================
Function Import_Regulator
Dim obj As AccessObject, dbs As Object
Dim i As Integer
Dim x As Integer
Dim strB2U1 As String
Dim strB2U2 As String
Dim strB2U3 As String
Dim strB2U4 As String
Dim table1 As String
Dim table2 As String
Dim table3 As String
Dim table4 As String
Set dbs = Application.CurrentData
i = 0
x = 0
table1 = "ProuctTable1"
table2 = "ProuctTable2"
table3 = "ProuctTable3"
table4 = "ProuctTable4"
For i = 1 To 21
For Each obj In dbs.AllTables
strB2U1 = "INSERT INTO" & " " & "[" & table1
& "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )" _
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'ab*';"
strB2U2 = "INSERT INTO" & " " & "[" &
table2 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'xf*';"
strB2U3 = "INSERT INTO" & " " & "[" &
table3 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate" _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'qw*';"
strB2U4 = "INSERT INTO" & " " & "[" &
table4 & "]" & " " & "( [Tracking Number], [Box No], [User Name], Date_Out )"
_
& " " & " SELECT" & " " & "F" & i & "," & "
'" & obj.Name & "' " & " AS BoxNo, UserName() AS UName, IssueDate " _
& " " & " FROM" & " " & "[" & obj.Name & "]" _
& " " & " WHERE " & " " & "F" & i & " " &
"Like 'up*';"
With DoCmd
.SetWarnings (False)
'
.RunSQL strB2U1
.RunSQL strB2U2
.RunSQL strB2U3
.RunSQL strB2U4
.SetWarnings (True)
End With
Next obj
Next i
End Function
'=====================================================
Regrds
Roger