By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

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

P: 24
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
Apr 26 '07 #1
Share this Question
Share on Google+
1 Reply


P: 37
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
Apr 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.