•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 391,913 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,740 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 1610 | Replies: 2
![]() |
u need to first open the database and assign its table's contents to a recordset object. all these u have to do in form_load event. try this code snippet :-
'in general section
dim db as database,rs as recordset
'in form_load event
set db=opendatabase(app.path & "\yourdbname.mdb")
set rs=db.openrecordset("yourtablename",dbopentable)
if rs.recordcount>0 then rs.movefirst
'in listbox click event
set rs=db.openrecordset("select roll from yourtablename where name='" & list1.text & "'",dbopendybaset)
if rs.recordcount>0 then
text1.text=rs("roll")
endif
set rs=nothing
'in general section
dim db as database,rs as recordset
'in form_load event
set db=opendatabase(app.path & "\yourdbname.mdb")
set rs=db.openrecordset("yourtablename",dbopentable)
if rs.recordcount>0 then rs.movefirst
'in listbox click event
set rs=db.openrecordset("select roll from yourtablename where name='" & list1.text & "'",dbopendybaset)
if rs.recordcount>0 then
text1.text=rs("roll")
endif
set rs=nothing
•
•
Join Date: Apr 2007
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
In vb form_load() put in code to which will fill your listbox with the database info :
'your code here to connect to db
'sql line to select from db
' sql = ("Select * from db_name")
rec.Open sql, cn, adOpenKeyset, adLockPessimistic
While Not rec.EOF
Me.listbox.AddItem rec(1).Value
rec.MoveNext
'click and data shows up in text box
Private Sub listbox_Click()
Dim sql As String
'connect to db
For intXfor = 0 To Me.listbox.ListCount - 1
'when user is selected populate data from table into txtboxes
If Me.listbox.Selected(intXfor) = True Then
sql = ( _
"Select * from db_name where row = '" _
& Me.listbox.List(intXfor) & "'")
rec.Open sql, cn, adOpenKeyset, adLockPessimistic
'display data in textbox
Me.textbox_name.Text = rec(0).Value
rec.Close
Set rec = Nothing
cn.Close
End If
Next
End Sub
'your code here to connect to db
'sql line to select from db
' sql = ("Select * from db_name")
rec.Open sql, cn, adOpenKeyset, adLockPessimistic
While Not rec.EOF
Me.listbox.AddItem rec(1).Value
rec.MoveNext
'click and data shows up in text box
Private Sub listbox_Click()
Dim sql As String
'connect to db
For intXfor = 0 To Me.listbox.ListCount - 1
'when user is selected populate data from table into txtboxes
If Me.listbox.Selected(intXfor) = True Then
sql = ( _
"Select * from db_name where row = '" _
& Me.listbox.List(intXfor) & "'")
rec.Open sql, cn, adOpenKeyset, adLockPessimistic
'display data in textbox
Me.textbox_name.Text = rec(0).Value
rec.Close
Set rec = Nothing
cn.Close
End If
Next
End Sub
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
access adsense advertising backup blogging bomb book business code coding combo copyright daniweb data database design development dropdownlist engine environment failure forum google malware marketing mcafee microsoft module monetization net news normalization privacy publishing reuse revenue search security server software spyware sql support survey technical video web webmaster wiki yahoo
- getting data from a list box. (Visual Basic 4 / 5 / 6)
- Search code in a database (Visual Basic 4 / 5 / 6)
- problem in listing directories in list box (Java)
- Drive List Box Help Please for Error 68 (Visual Basic 4 / 5 / 6)
- list box --php issue (PHP)
- "Error in linking List box with the VB6.0 database" (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to use webcam
- Next Thread: Accessing crystal report


Linear Mode