Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Help, Pleaseeeeeeee!!!

Status
Not open for further replies.

MichHart

Programmer
Dec 14, 2002
56
CA
I am sort of new to programming and definitely not an experienced one. I have four databases that I need to link to my program, but I have to do it using SQL code, and not data controls which I am accustomed to. I know I could pick it up if I had just a little sample of how it should go.

If anyone out there can give me an example of how I would take all data from a field in a table and place it in a listbox, I would greatly appreciate the hint.

Thanks in advance
Michelle
 
SQL Link

Dim db As Connection
Dim rs As Recordset

Set db = New Connection
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=S:\SELECT\Test Databases\Outbound Assistant V2\Outbound Assistant V2.mdb;" 'Database Path

rs.Open "SELECT [Advisor for Call 1], [Date Of Call 1], [Time Of Call 1], " _
& " [Action Taken For Call 1], FirstOfName, FirstOfMPN" _
& " From Data" _
& " WHERE (((Data.[Advisor for Call 1])='" & Name_To_Check & "') " _
& " AND ((Data.[Date Of Call 1])=#" & Date_Entered & "#))", db, adOpenStatic, adLockOptimistic ' Replace Fields I used with your own

Do Until rs.EOF

lstTime.AddItem rs.Fields(2)
lstMobile.AddItem rs.Fields(5)
lstName.AddItem rs.Fields(4)
lstOutcome.AddItem rs.Fields(3)

rs.MoveNext
Loop

Hope this helps. If you give me your email I will email you a project with one in
David Lerwill
"If at first you don't succeed go to the pub"
 
Something like
---------------------------
Set conn = New Connection
conn.Open YourConnectionString
Set rst = New Recordset
rst.Open "SELECT MyField1,MyField2 FROM tblMyTable WHERE tblMyField like 'a%'", conn
List1.Clear
If Not rst.EOF And Not rst.BOF Then
While Not rst.EOF
List1.AddItem rst.Fields("MyField1") & vbTab & rst.Fields("MyField2")
rst.MoveNext
Wend
Else
MsgBox "empty recordset"
End If
rst.Close
Set rst = Nothing
conn.Close
Set conn = Nothing
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thanks both of you for your quick reply. David my email addy is miahart135@hotmail.com

A sample project would be great.

Thanks
Michelle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top