Solved

Simple SQL Question

Posted on 1998-10-29
9
133 Views
Last Modified: 2010-04-30
Does someone have some code that would allow me to access a table in SQL and pass the information found into a textbox??? I need instructions on how to connect and perform the query.. I am very new to SQL.. I am however a fast learner. Any help would be appreciated
0
Comment
Question by:gcw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 3

Expert Comment

by:fguerreiro_inix
ID: 1442438
' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

' Open Database object from saved Microsoft Jet database
' for exclusive use.

Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _
True)

' Create a recordset to get all Employees
Set rstTemp = dbsNorthwind.OpenRecordset( "SELECT *      FROM Employees", dbOpenDynaset, dbReadOnly)

'Set the value of the textbox to Employee name
Textbox1.text = rstTemp("field_name")            

If you need some more explanation, ask for it before grading the question.
0
 

Author Comment

by:gcw
ID: 1442439
I need to access a SQL Table not an access Database
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1442440
Are you using RDO or DAO?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gcw
ID: 1442441
DAO
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 50 total points
ID: 1442442
Dim wrkODBC As Workspace  
Dim conPubs As Connection

Set conPubs = wrkODBC.OpenConnection("Connection1", _
      dbDriverNoPrompt, , _
      "ODBC;DATABASE=YourDatabase;UID=sa;PWD=;DSN=YourDSNName")
0
 

Author Comment

by:gcw
ID: 1442443
how do I get the information from the database and place into a textbox then? I will give more points...
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1442444
Dim MyRec as Recordset

Set MyRec = conPubs.OpenRecordset( "SELECT * FROM MyTable", dbOpenSnapshot)
if not Myrec.eof then
  Text1 = MyRec!MyField & vbnullstring
end if
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1442445
for instance.. flop a listbox on a form.

in the form_click event.. do this..
it will populate the listbox with the authors'last name from the authors table in your SQL Server Database..<assuming you didnt take it out>

Sub Form_click()
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim MyRec As Recordset
'assumes you have a Pubs DSN created for yourself
Set wrkODBC = CreateWorkspace("MySQLWorkspace", _
        "sa", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("", dbDriverPrompt, , _
      "ODBC;DATABASE=Pubs;UID=sa;PWD=;DSN=Pubs;")
Set MyRec = conPubs.OpenRecordset("SELECT au_lname FROM Authors", dbOpenSnapshot)

Do While Not MyRec.EOF
 List1.AddItem MyRec!au_lname & vbNullString
 MyRec.MoveNext
Loop
End Sub
0
 

Author Comment

by:gcw
ID: 1442446
thanks! this helps alot :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question