📄 adofind.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmFindMethod
Caption = "ADOFind"
ClientHeight = 6240
ClientLeft = 1650
ClientTop = 1545
ClientWidth = 6720
LinkTopic = "Form1"
ScaleHeight = 6240
ScaleWidth = 6720
Begin MSAdodcLib.Adodc adcOrders
Height = 330
Left = 2160
Top = 4560
Width = 2415
_ExtentX = 4260
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = ""
OLEDBString = ""
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Orders"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton cmdMove
Caption = "Move P&revious"
Enabled = 0 'False
Height = 375
Index = 3
Left = 5280
TabIndex = 10
Top = 5640
Width = 1215
End
Begin VB.CommandButton cmdMove
Caption = "Move N&ext"
Enabled = 0 'False
Height = 375
Index = 2
Left = 3600
TabIndex = 9
Top = 5640
Width = 1215
End
Begin VB.CommandButton cmdMove
Caption = "Move L&ast"
Height = 375
Index = 1
Left = 1920
TabIndex = 8
Top = 5640
Width = 1215
End
Begin VB.CommandButton cmdMove
Caption = "Move F&irst"
Height = 375
Index = 0
Left = 240
TabIndex = 7
Top = 5640
Width = 1215
End
Begin VB.TextBox txtStatus
Height = 285
Left = 4920
TabIndex = 6
Text = "Status"
Top = 4560
Width = 1575
End
Begin VB.CommandButton cmdFind
Caption = "Find &Previous"
Enabled = 0 'False
Height = 375
Index = 3
Left = 5280
TabIndex = 5
Top = 5040
Width = 1215
End
Begin VB.CommandButton cmdFind
Caption = "Find &Next"
Enabled = 0 'False
Height = 375
Index = 2
Left = 3600
TabIndex = 4
Top = 5040
Width = 1215
End
Begin VB.CommandButton cmdFind
Caption = "Find &Last"
Height = 375
Index = 1
Left = 1920
TabIndex = 3
Top = 5040
Width = 1215
End
Begin VB.CommandButton cmdFind
Caption = "Find &First"
Height = 375
Index = 0
Left = 240
TabIndex = 2
Top = 5040
Width = 1215
End
Begin MSDataGridLib.DataGrid dtgOrders
Bindings = "ADOFind.frx":0000
Height = 4215
Left = 240
TabIndex = 1
Top = 120
Width = 6255
_ExtentX = 11033
_ExtentY = 7435
_Version = 393216
AllowUpdate = 0 'False
HeadLines = 1
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 0
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 0
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.ComboBox cboCustomerID
Height = 315
Left = 240
Style = 2 'Dropdown List
TabIndex = 0
Top = 4560
Width = 1575
End
End
Attribute VB_Name = "frmFindMethod"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'---------------------------------------------------------------------------------------
' Module : frmFindMethod
' DateTime : 5/14/2002 15:30
' Author : Avaneesh Dvivedi
' Purpose : To demonstrate ADO Find, Move and Seek Method
'---------------------------------------------------------------------------------------
Option Explicit
Private cnnOrders As New ADODB.Connection
Private rstOrders As New ADODB.Recordset
Private strConnect As String
Private strSQL As String
Private Sub Form_Load()
'Open the connection
strConnect = App.Path & "\OR.mdb"
cnnOrders.Provider = "Microsoft.Jet.OLEDB.3.51"
cnnOrders.Open strConnect, "Admin" ', "Password", if the database is secure
'Load the combo list
strSQL = "SELECT DISTINCT CustomerID FROM Orders ORDER BY CustomerID"
Set rstOrders = cnnOrders.Execute(strSQL)
Do Until rstOrders.EOF
cboCustomerID.AddItem rstOrders.Fields(0).Value
rstOrders.MoveNext
Loop
cboCustomerID.ListIndex = 0
rstOrders.Close
End Sub
Private Sub Form_Activate()
'Populate the DataGrid
strSQL = "SELECT * FROM Orders WHERE OrderDate BETWEEN #1/1/95# AND #12/31/95#"
rstOrders.Open strSQL, cnnOrders, adOpenKeyset, adLockOptimistic, adCmdText
Set adcOrders.Recordset = rstOrders
End Sub
Private Sub cmdFind_Click(intIndex As Integer)
'Find records for the customer selected in cboCustomerID
Dim strCriteria As String
Dim lngSkipRecords As Long
Dim lngDirection As Long
Dim varStart As Variant
Dim varBookmark As Variant
strCriteria = "CustomerID = '" & cboCustomerID.List(cboCustomerID.ListIndex) & "'"
With rstOrders
Select Case intIndex
Case 0
'Find First
lngSkipRecords = 0
lngDirection = adSearchForward
varStart = adBookmarkFirst
cmdFind(2).Enabled = True
cmdFind(3).Enabled = False
Case 1
'Find Last
lngSkipRecords = 0
lngDirection = adSearchBackward
varStart = adBookmarkLast
cmdFind(2).Enabled = False
cmdFind(3).Enabled = True
Case 2
'Find Next
lngSkipRecords = 1
lngDirection = adSearchForward
varStart = adBookmarkCurrent
cmdFind(3).Enabled = True
Case 3
'Find Previous
lngSkipRecords = 1
lngDirection = adSearchBackward
varStart = adBookmarkCurrent
cmdFind(2).Enabled = True
End Select
varBookmark = .Bookmark
.Find strCriteria, lngSkipRecords, lngDirection, varStart
If .EOF Then
txtStatus.Text = "Not Found (EOF)"
.Bookmark = varBookmark
Beep
ElseIf .BOF Then
txtStatus.Text = "Not Found (BOF)"
.Bookmark = varBookmark
Beep
Else
txtStatus.Text = "Found " & cboCustomerID.List(cboCustomerID.ListIndex)
End If
End With
End Sub
Private Sub cmdMove_Click(intIndex As Integer)
'Use Move with code similar to that for the Find method
Dim lngSkipRecords As Long
Dim varStart As Variant
Dim varBookmark As Variant
With rstOrders
Select Case intIndex
Case 0
'Move First
lngSkipRecords = 0
varStart = adBookmarkFirst
cmdMove(2).Enabled = True
cmdMove(3).Enabled = False
Case 1
'Move Last
lngSkipRecords = 0
varStart = adBookmarkLast
cmdMove(2).Enabled = False
cmdMove(3).Enabled = True
Case 2
'Move Next
lngSkipRecords = 1
varStart = adBookmarkCurrent
cmdMove(3).Enabled = True
Case 3
'Move Previous
lngSkipRecords = -1
varStart = adBookmarkCurrent
cmdMove(2).Enabled = True
End Select
varBookmark = .Bookmark
.Move lngSkipRecords, varStart
If .EOF Then
txtStatus.Text = "At EOF"
.Bookmark = varBookmark
Beep
ElseIf .BOF Then
txtStatus.Text = "At BOF"
.Bookmark = varBookmark
Beep
Else
txtStatus.Text = "Valid Row"
End If
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -