📄 frmdbshow.frm
字号:
VERSION 5.00
Begin VB.Form FrmDBshow
Caption = "检索数据库,选择需要导出的字段"
ClientHeight = 3420
ClientLeft = 60
ClientTop = 345
ClientWidth = 6690
Icon = "FrmDbShow.frx":0000
LinkTopic = "Form2"
ScaleHeight = 3420
ScaleWidth = 6690
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Caption = "字段分隔符"
Height = 615
Left = 0
TabIndex = 10
Top = 2760
Width = 4695
Begin VB.OptionButton optsp
Caption = """,""号"
Height = 255
Index = 2
Left = 1920
TabIndex = 15
Top = 240
Width = 855
End
Begin VB.TextBox Txtspchar
Height = 270
Left = 3960
TabIndex = 13
Top = 240
Width = 615
End
Begin VB.OptionButton optsp
Caption = "TAB键"
Height = 255
Index = 1
Left = 120
TabIndex = 12
Top = 240
Value = -1 'True
Width = 975
End
Begin VB.OptionButton optsp
Caption = "空格"
Height = 255
Index = 0
Left = 1080
TabIndex = 11
Top = 240
Width = 855
End
Begin VB.Label Label2
Caption = "自定义:"
Height = 255
Left = 3120
TabIndex = 14
Top = 285
Width = 735
End
End
Begin VB.CommandButton Command1
Caption = "取消"
Height = 375
Left = 5880
TabIndex = 9
Top = 2880
Width = 735
End
Begin VB.CommandButton cmdsel
Caption = "<-"
Enabled = 0 'False
Height = 375
Index = 1
Left = 4140
TabIndex = 5
Top = 1665
Width = 555
End
Begin VB.CommandButton cmdsel
Caption = "->"
Enabled = 0 'False
Height = 375
Index = 0
Left = 4140
TabIndex = 4
Top = 810
Width = 555
End
Begin VB.ListBox List3
Height = 2040
Left = 4770
TabIndex = 3
Top = 315
Width = 1905
End
Begin VB.CommandButton cmdll
Caption = "导出"
Default = -1 'True
Height = 375
Left = 4920
TabIndex = 2
Top = 2880
Width = 795
End
Begin VB.ListBox List2
Height = 2040
Left = 2205
TabIndex = 1
Top = 315
Width = 1890
End
Begin VB.ListBox List1
Height = 2040
Left = 0
TabIndex = 0
Top = 315
Width = 2190
End
Begin VB.Line Line1
BorderColor = &H00FFFFFF&
Index = 1
X1 = 0
X2 = 6600
Y1 = 2660
Y2 = 2660
End
Begin VB.Line Line1
BorderColor = &H00404040&
Index = 0
X1 = 0
X2 = 6600
Y1 = 2640
Y2 = 2640
End
Begin VB.Label Label1
Caption = "包含字段:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 2
Left = 4770
TabIndex = 8
Top = 45
Width = 1320
End
Begin VB.Label Label1
Caption = "可用字段:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 1
Left = 2250
TabIndex = 7
Top = 45
Width = 870
End
Begin VB.Label Label1
Caption = "数据库表:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 0
Left = 45
TabIndex = 6
Top = 45
Width = 870
End
End
Attribute VB_Name = "FrmDBshow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'*********************************************************************
'*
'* 本源码完全免费,共交通同仁学习参考 *
'* www.tranbbs.com *
'* Developed by Yang Ming *
'* Nanjing Institute of City Transportation Planning *
'* 请保留本版权信息,谢谢合作 *
'* 中国交通技术论坛 *
'* *
'* *
'*********************************************************************
Option Explicit
Private Sub cmdsel_Click(Index As Integer)
On Error GoTo b0:
Select Case Index
Case 0
'把List2中需要查询的字段,向List3列表框中添加,
'以便于用其来构造SQL语句。
If List2.ListCount = 1 Then cmdsel(0).Enabled = False
cmdsel(1).Enabled = True
List3.AddItem List2.Text
List2.RemoveItem List2.ListIndex
List2.Selected(List2.ListIndex + 1) = True
List3.Selected(List3.NewIndex) = True
Case 1
'把List3中不需要查询的字段移去。
If List3.ListCount = 1 Then cmdsel(1).Enabled = False
cmdsel(0).Enabled = True
List2.AddItem List3.Text
List3.RemoveItem List3.ListIndex
List3.Selected(List3.ListIndex + 1) = True
List2.Selected(List2.NewIndex) = True
b0:
End Select
End Sub
Private Sub cmdll_Click()
Dim i As Integer
Dim SpChar As String
If Txtspchar <> "" Then
SpChar = Txtspchar.Text
Else
If optsp(0).Value = True Then
SpChar = vbTab
ElseIf optsp(1).Value = True Then
SpChar = " "
ElseIf optsp(2).Value = True Then
SpChar = ","
End If
End If
'构造SQL语句。
If List3.ListCount > 0 Then
For i = 0 To List3.ListCount - 1
List3.Selected(i) = True
'SQL语句有严格的语法要求,如果要查询的字段的字段名中
'包含有空格或其他的特殊字符,一定要要用ASCII码为96的
'字符(即Esc键的下面那个键)将它括起来,以免导致查询失败。
If InStr(1, List3.Text, " ") <> 0 Then
SQL_str = SQL_str & TbName & "." & "`" & List3.Text & "`" & ","
Else
SQL_str = SQL_str & TbName & "." & List3.Text & ","
End If
Next i
SQL_str = Left(SQL_str, Len(SQL_str) - 1)
SQL_str = "SELECT " & SQL_str & " FROM " & TbName
End If
Dim Rstemp As Recordset
Dim FidCount As Integer
Set Rstemp = mDbBiblio.OpenRecordset(SQL_str)
FidCount = Rstemp.Fields.Count
Rstemp.MoveFirst
Open ExportPath & ExportName For Output As #1
Dim tempstr
Do Until Rstemp.EOF
tempstr = ""
For i = 0 To FidCount - 1
tempstr = tempstr & Rstemp.Fields(i) & SpChar
Next i
Print #1, tempstr
Rstemp.MoveNext
Loop
Close #1
Dim RespView
RespView = MsgBox("输出导出成功,是否需要查看所导出的文件?", vbOKCancel, "数据导出成功")
If RespView = vbOK Then
Dim OpenF
OpenF = "NotePad.EXE " & ExportPath & ExportName
Shell OpenF, vbNormalFocus
End If
Unload Me
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim x, tdf
For x = 0 To mDbBiblio.TableDefs.Count - 1
Set tdf = mDbBiblio.TableDefs(x)
If (tdf.Attributes And dbSystemObject) = 0 Then '避开系统的 Table
List1.AddItem mDbBiblio.TableDefs(x).Name
End If
Next
SQL_str = ""
End Sub
Private Sub List1_Click()
List2.Clear
List3.Clear
'遍历表中的字段,将其字段名添加到 List2 中。
For Each Fd In mDbBiblio.TableDefs(List1.Text).Fields
List2.AddItem Fd.Name
Next
'控制cmdsel按钮数组的有效性,以免发生错误。
If List2.ListCount <> 0 Then
cmdsel(0).Enabled = True
List2.Selected(0) = True
Else
cmdsel(0).Enabled = False
End If
'获取要查询的表名。
TbName = List1.Text
End Sub
Private Sub optsp_Click(Index As Integer)
Txtspchar.Text = ""
End Sub
Private Sub Txtspchar_Change()
Dim i
For i = 0 To 2
optsp(i).Value = False
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -