You are on page 1of 3

Option Explicit Dim conn As ADODB.Connection, rec As ADODB.

Recordset Dim esql As String, esql2 As String, searchvar As String Private Sub Command1_Click() Text1 = "" Text2 = "" Text3 = "" Command4.Visible = True Command1.Visible = False Text1.SetFocus End Sub Private Sub Command2_Click() If Not rec.EOF Then rec.MoveNext Else rec.MoveLast End If GetText End Sub Private Sub Command3_Click() If Not rec.BOF Then rec.MovePrevious Else rec.MoveFirst End If GetText End Sub Private Sub Command4_Click() On Error GoTo 1 If Text1 = "" Or Text2 = "" Then Command4.Visible = False Command1.Visible = True Exit Sub End If rec.AddNew rec.Fields(0) = Text1 rec.Fields(1) = Text2 rec.Fields(2) = Text3 rec.Update If Not rec.EOF Then rec.MoveNext rec.MoveFirst GetText Command4.Visible = False Command1.Visible = True Exit Sub 1 MsgBox ("duplicate value") & Text3 End Sub Private Sub Command5_Click() Text1 = "" Text2 = "" Text3 = "" searchvar = InputBox("enter item to find")

rec.Close rec.Open ("select * from TestRavi where First=" & "'" & searchvar & "'"), conn, adOpenStatic, adLockReadOnly If rec.Fields(0) <> "" Then Text1 = rec.Fields(0) Text2 = rec.Fields(1) Text3 = rec.Fields(2) Else MsgBox ("No matching records found") rec.Close rec.Open ("select * from testravi"), conn, adOpenDynamic, adLockOptimistic GetText End If End Sub 'for integers use 'Dim searchvar2 As Integer 'searchvar2 = InputBox("enter Number") 'rec.Open ("select * from TestRavi where First=" & searchvar2), conn, adOpenStatic, adLockReadOnly Private Sub Form_Load() Set conn = New ADODB.Connection Set rec = New ADODB.Recordset 'conn.Open ("Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb;Persist Security Info=False") conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb;Persist Security Info=False" conn.Open esql = "select * from TestRavi" rec.Open (esql), conn, adOpenDynamic, adLockOptimistic GetText End Sub Private Sub Form_Unload(Cancel As Integer) rec.Close conn.Close Set conn = Nothing command1.visible=false End Sub Private Sub GetText() If rec.BOF = True Or rec.EOF = True Then Exit Sub Text1 = rec.Fields(0) Text2 = rec.Fields(1) Text3 = "" End Sub

Function RandomString(cb As Integer) As String Randomize Dim rgch As String rgch = "abcdefghijklmnopqrstuvwxyz" rgch = rgch & UCase(rgch) & "0123456789" Dim i As Long For i = 1 To cb RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1) Next End Function

Public Function RandomString( _ ByVal length As Long, _ Optional charset As String = "abcdefghijklmnopqrstuvwxyz0123456789" _ ) As String Dim chars() As Byte, value() As Byte, chrUprBnd As Long, i As Long If length > 0& Then Randomize chars = charset chrUprBnd = Len(charset) - 1& length = (length * 2&) - 1& ReDim value(length) As Byte For i = 0& To length Step 2& value(i) = chars(CLng(chrUprBnd * Rnd) * 2&) Next End If RandomString = value End Function

You might also like