|
-
Sep 23rd, 2003, 05:52 PM
#1
Thread Starter
Giants World Champs!!!!
Combo Box and SQL
I have been trying to populate a combo box with the data contained in a table in a MS SQL Database. I have searched the BB for this information but I was unable to combine the posts in a manner that made sense to me.
I have a table located in SQL called Current_Users that I have linked to my vb project via the dataenvironment1. This table contains two (2) fields; UserName and P_Word. I want to use contains of the UserName field to populate ComboBox1. How can I accomplish this?
Thank You,
Mark
-
Sep 23rd, 2003, 06:02 PM
#2
Frenzied Member
VB Code:
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSql As String
Set conn = "Driver={SQL Server};Server=ServerName;Database=dbName;Uid=Username;Pwd=password;"
Set strSql = "SELECT * FROM Current_Users"
rs.Open(strSql, conn, 3, 3)
If(rs.eof) then
MsgBox("There are no records in the database")
Else
do until rs.eof
combobox1.Add rs("Username") 'add the field to the combobox
rs.movenext
loop
End
rs.Close
conn.Close
Set rs = nothing
Set conn = nothing
Set strSql = nothing
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Sep 23rd, 2003, 06:19 PM
#3
Thread Starter
Giants World Champs!!!!
References
I am now getting an error regarding the line:
Dim conn As ADODB.Connection
Error:
Compile Error
User Defined Type Not Defined
I have the Microsoft ADO Ext. 2.7 for DLL and Security reference loaded.
Any suggestions?
Mark
Last edited by Mark Gambo; Sep 23rd, 2003 at 06:35 PM.
-
Sep 24th, 2003, 11:38 AM
#4
Frenzied Member
add a reference to Microsoft ADO 2.x library.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Sep 24th, 2003, 12:31 PM
#5
Thread Starter
Giants World Champs!!!!
Combo Box
Thanks, it worked like a champ!
I am using this combo box to so that the user can select a his/her name from the drop down list. I would like them to be able to type the first letter of the last name form in order for them to select there name.
i.e., List
AAronn, John
Abhrams, Roberta
Able, Edward
Adams, Sara
I want Edward Able to press the "A" key three (3) times in order to select his name.
How can I do this?
Regards,
Mark
-
Sep 24th, 2003, 01:10 PM
#6
Addicted Member
try this:
Dim Backspaced As Boolean
Private Sub cboNom_Change()
If Backspaced = True Or cboNom.Text = "" Then
Backspaced = False
Exit Sub
End If
Dim i As Long
Dim nSel As Long
For i = 0 To cboNom.ListCount - 1
If InStr(1, cboNom.List(i), cboNom.Text, _
vbTextCompare) = 1 Then
nSel = cboNom.SelStart
cboNom.Text = cboNom.List(i)
cboNom.SelStart = nSel
cboNom.SelLength = Len(cboNom.Text) - nSel
Exit For
End If
Next
End Sub
Private Sub cboNom_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then
If cboNom.Text <> "" Then
Backspaced = True
End If
End If
End Sub
-
Sep 24th, 2003, 01:13 PM
#7
Addicted Member
ops I didn't read your post very well at first beginning the code I post is for autocompleting but let me know if you really need only one character of first name so I'll modify if you think the one I sent is better then cheers
Hope it helps.
-
Sep 24th, 2003, 01:22 PM
#8
Thread Starter
Giants World Champs!!!!
Thanks for the code!
Yeah, I was looking for the user to continue to press the letter of the last name until there get the name they are looking for.
Thank you again!!!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Sep 24th, 2003, 01:46 PM
#9
Addicted Member
LoL
hi man
this is so funny, I never notice, default ComboBox does already have that thing, I just started to do that but it does have it.
have you ever give it a try?
Hope it helps.
-
Sep 24th, 2003, 02:19 PM
#10
Thread Starter
Giants World Champs!!!!
I tried it before and it would not work. I'll create a new one and see if it works. Thanks again.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Sep 24th, 2003, 04:48 PM
#11
Thread Starter
Giants World Champs!!!!
vb,
I tried it and I could not get it to work. I tried your code and the autocomplete will be handy for another portion of my program. Do you know what I could be doing wrong regarding my original post?
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Sep 25th, 2003, 07:41 AM
#12
Fanatic Member
Set the Style property on your Combo box to 2 - Dropdown List.
Chris
Master Of My Domain
Got A Question? Look Here First
-
Sep 25th, 2003, 01:33 PM
#13
Thread Starter
Giants World Champs!!!!
That did the trick, Thanks
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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
|