📄 select5.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Chapter 3.5 Example"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 5340
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 5340
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtParameter
Height = 285
Left = 1530
TabIndex = 5
Top = 60
Width = 585
End
Begin VB.CommandButton cmdClose
Caption = "&Close"
Height = 525
Left = 4020
TabIndex = 4
Top = 2580
Width = 1245
End
Begin VB.CommandButton cmdSearch
Caption = "&Search"
Height = 525
Left = 2520
TabIndex = 3
Top = 2580
Width = 1245
End
Begin VB.ListBox lstResults
Height = 1815
Left = 60
TabIndex = 0
Top = 630
Width = 5205
End
Begin VB.Label lblResults
Caption = "Results:"
Height = 195
Left = 60
TabIndex = 2
Top = 420
Width = 1635
End
Begin VB.Label lblParameter
Caption = "State abbreviation:"
Height = 195
Left = 60
TabIndex = 1
Top = 90
Width = 1635
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const BIBLIO_PATH = "D:\Program Files\Microsoft Visual Studio\VB6\Biblio.MDB"
Private mdbfBiblio As Database
Private mrecSelect As Recordset
Private mqdfTemp As QueryDef
Private Sub cmdClose_Click()
End
End Sub
Private Sub cmdSearch_Click()
Dim lstrTemp As String
'Set the parameter to the contents of our text box
mqdfTemp![pstrState] = txtParameter.Text
'If we haven't run this query yet, we'll need to
'create it. If we have, we don't need to create it,
'just to requery it.
If mrecSelect Is Nothing Then
Set mrecSelect = mqdfTemp.OpenRecordset()
Else
mrecSelect.Requery mqdfTemp
End If
'Clear the list box
lstResults.Clear
'Populate the list box with names & phone numbers
If mrecSelect.RecordCount > 0 Then
mrecSelect.MoveFirst
Do Until mrecSelect.EOF
lstResults.AddItem mrecSelect![Name] & " (Phone: " & mrecSelect![Telephone] & ")"
mrecSelect.MoveNext
Loop
End If
End Sub
Private Sub Form_Load()
'Open a Database object first - the familiar BIBLIO.MDB
Set mdbfBiblio = DBEngine.Workspaces(0).OpenDatabase(BIBLIO_PATH)
'Use the CreateQueryDef method to create a temporary QueryDef object
'that will store our parameter query. The best way to use a parameter
'query in DAO is with the QueryDef object.
Set mqdfTemp = mdbfBiblio.CreateQueryDef("")
'Set the SQL property to our parameter query SQL statement.
mqdfTemp.SQL = "PARAMETERS pstrState String;SELECT [Name],[Telephone] " & _
"FROM [Publishers] WHERE [State] = [pstrState] " & _
"ORDER By [Name]"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -