Connecting Tech Pros Worldwide Forums | Help | Site Map

how to show the results of MS Access database query in Visual basic

Newbie
 
Join Date: Nov 2006
Posts: 23
#1: Apr 26 '07
Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:

Dim db As Database
Dim rec As Recordset

Private Sub Command1_Click()
Set db = OpenDatabase("the patht of database")
MsgBox "database is open"
Set rec = db.OpenRecordset("SELECT DISTINCT asmenu_info.Vardas FROM asmenu_info;")
While Not rec.EOF
Label1.Print rec!vardas
rec.MoveNext
Wend
rec.Close
db.Close
End Sub

If i do this with second form everythig is ok, but I want to do this with label or text box

Banned
 
Join Date: Apr 2006
Posts: 37
#2: Apr 27 '07

re: how to show the results of MS Access database query in Visual basic


Hi,

Private Sub Form_Load()
Set rsgroup = New ADODB.Recordset
Set rsaccount = New ADODB.Recordset
rsgroup.CursorLocation = adUseClient
rsaccount.CursorLocation = adUseClient
rsgroup.Open “SELECT * FROM NGROUP WHERE GHIDDEN <> -1”, CN, adOpenDynamic, adLockOptimistic, adCmdText
rsaccount.Open “SELECT * from PARTY”, CN, adOpenDynamic, adLockOptimistic
If rsaccount.RecordCount > 0 Then
Do While rsaccount.EOF = False
List1.AddItem rsaccount(“pname”)
rsaccount.MoveNext
Loop
rsaccount.MoveFirst
End If
If rsaccount.RecordCount > 0 Then
mname = rsaccount!PName
mdes = rsaccount!pdes
madd1 = rsaccount!address1
madd2 = rsaccount!address2
mphone = rsaccount!phone
mfax = rsaccount!fax
mcity = rsaccount!city
mamount = rsaccount!opamt
End If
mname.Enabled = False
mdes.Enabled = False
madd1.Enabled = False
madd2.Enabled = False
mcity.Enabled = False
mphone.Enabled = False
mfax.Enabled = False
mamount.Enabled = False
savebutton.Enabled = False
cancelbutton.Enabled = False
Newbutton.Enabled = True
Editbutton.Enabled = True
deletebutton.Enabled = True
End Sub

Database programming in Visual basic
Reply