|
-
Apr 5th, 2004, 08:29 PM
#1
Thread Starter
New Member
Connecting to Access
I'm using an access 2000 and I need to get information from the database to VB, I used the data control, to display employee last name in a combo box, it only shows the first last and nothing else, how can get the whole list in the combo box to choose from?
Thank you for your help
-
Apr 6th, 2004, 03:03 AM
#2
-= B u g S l a y e r =-
Hi adnane,
first of all, never use the bound datacontrol. Its evil. Learn how to do it the proper way, using ADO
sample
VB Code:
Public Const strJetProvider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\myaccess.mdb"
'Usage
'* Place on a form a combo box and a command button
Public Sub Command1_Click()
Dim MyConn As New ADODB.Connection
Dim MyRst As New ADODB.Recordset
Dim strTemp As String
With MyConn
.ConnectionString = strJetProvider
.Open
End With
With Me
.Combo1.Clear
End With
MyRst.Open "SELECT * FROM SQL", MyConn, adLockReadOnly, adLockOptimistic, adCmdText
If MyRst.RecordCount <= 0 Then
MyRst.Close
MyConn.Close
Set MyRst = Nothing
Set MyConn = Nothing
strTemp = MsgBox("Sorry No Records are located?", vbOKOnly + vbCritical, "No Records Found")
Exit Sub
End If
Do While Not MyRst.EOF
If Not IsNull(MyRst("Field")) Then
Combo1.AddItem MyRst("Field")
End If
MyRst.MoveNext
Loop
MyRst.Close
If Combo1.ListCount > 0 Then
Combo1.ListIndex = 0
End If
End Sub
you have to learn some more in order to understand, but once you get going you will see its the right thing to do.
-
Apr 6th, 2004, 03:05 AM
#3
-= B u g S l a y e r =-
-
Apr 7th, 2004, 06:06 PM
#4
Thread Starter
New Member
Thanks peet for your reply, I appreciate it, I will use the ADO instead.
I have one more question, I need to select an item from the combo box and display some information in some text boxes, when you click on the button, it'll save the information to the database.
Thanks again for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|