Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

binding textboxes to database fields via code

Status
Not open for further replies.

Catrina

Programmer
Feb 11, 2000
70
US
I need some help with displaying Database information. I am just learning
to use VB with databases. I have a datagrid that is populated via
code.

Dim sSQL As String

Set objAccessConnection = New ADODB.Connection
objAccessConnection.CursorLocation = adUseClient

objAccessConnection.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
" Data Source=c:\test\lesson6\custlist.mdb;"

sSQL = "select * from cust"

Set rsAccess = New ADODB.Recordset
rsAccess.Open sSQL, objAccessConnection, adOpenKeyset, adLockOptimistic

Set grdLedger.DataSource = rsAccess

''Works fine


I also have a command button users can click to find a record. When clicked
an input box is used to gather the search critria. I then want to
be able to pop up a hidden frame showing the resulting record. The search works, it moves to
the named record in the datagrid, but I want all fields
in textboxes (I don't know how to link the textboxes to the database
via code). I need the user to be able to edit the found file. Eventually I want to
get rid of the datagrid, but just learning, I am using it as most examples use some
type of grid. Here is the command button code.

Private Sub cmdEdit_Click()
Dim stClient As String


stClient = InputBox("Enter Client Number", "Edit Client")
If stClient <> &quot;&quot; Then

With rsAccess
.MoveFirst
.Find &quot;Client='&quot; & stClient & &quot;'&quot;, , , 0
End With
Else
MsgBox &quot;No Client Number entered&quot;
Exit Sub
End If
''Need to set found records into the text boxes
'txtClient.....
'txtPass......
'txtComm......
Frame1.Visible = True
End Sub


Thanks in advance for any help.

Catrina
 
You can use DataSource and DataField properties of Textbox to bind them to the recordset.


Set Text1.DataSource = rsAccess
Text1.DataField = &quot;Client&quot;
 
I feel stupid now! I had tried to use DataSource, but kept getting an error. I forgot to use Set. Works fine now thanks.

Catrina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top