What does this Visual Basic 6.0 code below do? However it has been used for a search function, I'm not clear with it. So please explain what it does.
Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Employee No whose details u want to know: ")
Set rs = Nothing
str = "select * from emp where e_no=" & key
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
txtNo.Text = rs(0)
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
End Sub
The point no one yet has explicitly said is rs must be declared As New RecordSet so that the Set rs = Nothing just means effectively the same as Set rs = New RecordSet.
Private Sub cmdSearch_Click()
Dim key As Integer, str As String
key = InputBox("Enter the Employee No whose details u want to know: ") ''// query the user for a name
Set rs = Nothing
str = "select * from emp where e_no=" & key ''//create sql query on the fly
rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly ''// create a connection to an sql database
txtNo.Text = rs(0) ''//assign the results of the query to input fields or labels
txtName.Text = rs(1)
txtCity.Text = rs(2)
txtDob.Text = rs(4)
txtPhone.Text = rs(3)
Set rs = Nothing
str = "select * from emp"
rs.Open str, adoconn, adOpenDynamic, adLockPessimistic ''// creates a new sql connection and load the whole emp table
End Sub
Short summary: Ask the user for a name and display the data of the user in labels or textboxes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With