Microsoft KB Archive/113954

How to Use FindFirst Method with Numbers, Strings, & Dates

PSS ID Number: Q113954 Article last modified on 04-25-1994

3.00 WINDOWS

= SUMMARY =

This article shows by example how to use the FindFirst method with a data control. In the example, you’ll see the three different FindFirst methods for working with numbers, strings, and dates. The code is designed to be used to compare the three different FindFirst methods to search for certain data types in a database.

= MORE INFORMATION =

Example Showing How to Use FindFirst with Date, Text, & Integer Data Types

 * 1) Start a new project in Visual Basic. Form1 is created by default.
 * 2) Below is the FORM1.FRM file saved as text. Bring the text into a text editor and save the file as FORM1.FRM. Then remove the default Form1 from the project, and add the FORM1.FRM file you just saved. Then go to the Options menu and choose Form1 as your startup form. NOTE: There are lines below that need to be on one, single line. Be sure to put them on one line before bringing them into Visual Basic. VERSION 2.00 Begin Form Form1 Caption = “FindFirst with Numbers, Strings & Dates” ClientHeight = 3945 ClientLeft = 1095 ClientTop = 1560 ClientWidth = 7365 Height = 4350 Left = 1035 LinkTopic = “Form1” ScaleHeight = 3945 ScaleWidth = 7365 Top = 1215 Width = 7485 Begin TextBox Text6 DataField = “Date Published” DataSource = “Data1” Height = 375 Left = 6240 TabIndex = 15 Top = 2520 Width = 975 End Begin CommandButton Command3 Caption = “Press to search date” Height = 495 Left = 5040 TabIndex = 13 Top = 1200 Width = 2175 End Begin TextBox Text5 Height = 375 Left = 6000 TabIndex = 12 Top = 600 Width = 1215 End Begin TextBox Text4 DataField = “Title” DataSource = “Data1” Height = 375 Left = 3000 TabIndex = 9 Top = 2520 Width = 1815 End Begin TextBox Text3 Height = 375 Left = 1200 TabIndex = 0 Top = 600 Width = 1095 End Begin TextBox Text2 DataField = “PubID” DataSource = “Data1” Height = 375 Left = 1200 TabIndex = 3 Top = 2520 Width = 615 End Begin TextBox Text1 Height = 375 Left = 3600 TabIndex = 2 Top = 600 Width = 1215 End Begin CommandButton Command2 Caption = “Press to search name” Height = 495 Left = 2640 TabIndex = 4 Top = 1200 Width = 2055 End Begin Data Data1 Caption = “Data1” Connect = &quot;&quot; DatabaseName = “C:.MDB” Exclusive = 0 ’False Height = 375 Left = 2280 Options = 0 ReadOnly = -1 ’True RecordSource = “Titles” Top = 3360 Width = 2535 End Begin CommandButton Command1 Caption = “Press to search number” Height = 495 Left = 120 TabIndex = 1 Top = 1200 Width = 2175 End Begin Label Label7 Caption = “Date Published—>” Height = 495 Left = 4920 TabIndex = 14 Top = 2520 Width = 1215 End Begin Label Label6 Caption = “Enter Date Published to Search—>” Height = 855 Left = 4920 TabIndex = 11 Top = 120 Width = 975 End Begin Label Label5 Caption = “Results of Search Below” FontBold = -1 ’True FontItalic = -1 ’True FontName = “MS Sans Serif” FontSize = 12 FontStrikethru = 0 ’False FontUnderline = 0 ’False Height = 375 Left = 2040 TabIndex = 10 Top = 1920 Width = 3255 End Begin Label Label4 Caption = “Title Name—->” Height = 375 Left = 2160 TabIndex = 8 Top = 2520 Width = 975 End Begin Label Label3 Caption = “PubID—>” Height = 255 Left = 120 TabIndex = 7 Top = 2520 Width = 975 End Begin Label Label2 Caption = “Enter PubID Number to Search—->” Height = 615 Left = 120 TabIndex = 6 Top = 240 Width = 1095 End Begin Label Label1 Caption = “Enter Title to Search—->” Height = 615 Left = 2400 TabIndex = 5 Top = 240 Width = 1095 End End Sub Command1_Click  Dim findrecid% findrecid% = Val(text3.Text) data1.Recordset.FindFirst “PubID =” & findrecid% & &quot;&quot; text1.Text = &quot;&quot; text5.Text = &quot;&quot; End Sub Sub Command2_Click  Dim findrecid As String findrecid = text1.Text & “&quot; data1.Recordset.FindFirst &quot;Title like ’&quot; & findrecid & &quot;‘&quot; text5.Text = &quot;&quot; text3.Text = &quot;&quot; End Sub Sub Command3_Click  Dim findrecid$ findrecid$ = text5.Text’** the next two lines should be on one line data1.Recordset.FindFirst”[Date Published] = #&quot; & DateValue(findrecid$) & “#” text3.Text = &quot;&quot; text1.Text = &quot;&quot; End Sub
 * 3) From the Run menu, choose Start (ALT, R, S), or press the F5 key to run the program. Enter a number 1-30 in the Text1 box. Then click the Command1 button. Enter a title or first letter in the Text2 box. Then click the Command2 button. Enter a date in MM/DD/YY format in the Text3 box. Then click the Command3 button.

Additional reference words: 3.00 KBCategory: KBSubcategory: APrgDataAcc ============================================================================= Copyright Microsoft Corporation 1994.