VBA - Search for a field and display all the fields
After reading through some of posts thought this is the best place I can learn VBA
there are lots of doubts,,,
1) Following was my code to insert records...This works fine.
|Private Sub CommandButton2_Click() |
Dim Cn As ADODB.Connection '* Connection String
Dim oCm As ADODB.Command '* Command Object
Dim sName As String
Dim sLocation As String
Dim iRecAffected As Integer
Dim rs As ADODB.Recordset 'On Error GoTo ADO_ERROR Set
Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\test2.accdb;Persist Security Info=False" Cn.ConnectionTimeout = 40
Cn.Open Set oCm = New ADODB.Command
oCm.ActiveConnection = Cn
Set rs = New ADODB.Recordset 'Set db =
OpenDatabase("d:\test2.accdb", False, False, ";pwd=") '
Set rs = OpenDatabase.OpenRecordset("SampleTable")
rs.Open "SampleTable", Cn, adOpenKeyset, adLockPessimistic, adCmdTable
rs("UserName") = TextBox1.Text
rs("Location") = TextBox2.Text
'Checking IF cond If rs("Location") = "Great" Then rs("Location") = "King" End If
'Display Location in TextBox3
TextBox3.Text = rs("Location")
Im sure most of you would hav understood in 1 second...
2) Since the 1st one looked v.simple, I want something similar for searching for a particular field in the table...
eg: I will enter the data in TextBox2.... and remaining TextBoxes have to be populated based on what I enter in TextBox2
I understand the SQL equivalent for it is
select * from SampleTable where rs("Location") = TextBox2.Text;
Pls help me...
I have few more doubts in coming days...
16-04-2011 at 07:11 AM