1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| Private Function CreateSQL() As String
Dim fsObject As Scripting.FileSystemObject
Dim fsFile As Scripting.TextStream
Dim strLine As String
Dim strSQL As Variant
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set fsFile = fsObject.OpenTextFile("C:\tbdump.txt", ForReading, False)
Do While Not fsFile.AtEndOfStream
strLine = fsFile.ReadLine
If Left(strLine, 12) = "CREATE TABLE" Then
Do While Not strLine = ");"
strSQL = strSQL & strLine
strLine = fsFile.ReadLine
Loop
End If
Loop
strSQL = Replace(strSQL, Chr(34), "")
strSQL = Replace(strSQL, "DEFAULT '' ", "")
strSQL = Replace(strSQL, "TEXT", "MEMO")
strSQL = Replace(strSQL, "VARCHAR", "CHAR")
strSQL = Replace(strSQL, " ", " ")
strSQL = Replace(strSQL, "NOT NULL", "")
Open "C:\test.txt" For Output As #1
Write #1, strSQL
Close #1
DoCmd.RunSQL strSQL & ");"
fsFile.Close
End Function
Private Function InsertSQL() As String
Dim fsObject As Scripting.FileSystemObject
Dim fsFile As Scripting.TextStream
Dim strLine As String
Dim strSQL As Variant
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set fsFile = fsObject.OpenTextFile("C:\tbdump.txt", ForReading, False)
strLine = fsFile.ReadLine
Do While Not Left(strLine, 11) = "INSERT INTO"
strLine = fsFile.ReadLine
Loop
If Left(strLine, 11) = "INSERT INTO" Then
Do While Left(strLine, 11) = "INSERT INTO"
strSQL = strLine
Do While Not Right(strLine, 2) = ");"
strLine = fsFile.ReadLine
strSQL = strSQL & vbNewLine & strLine
Loop
strSQL = Replace(strSQL, Chr(34), "")
strSQL = Replace(strSQL, "\'", "`")
strSQL = Replace(strSQL, "'\`", "'\'")
DoCmd.RunSQL strSQL
If fsFile.AtEndOfStream Then Exit Do
strLine = fsFile.ReadLine
Loop
Else
MsgBox "end?", vbOKOnly
End If
fsFile.Close
End Function |