Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple SQL Question

Posted on 1998-10-29
9
Medium Priority
?
136 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:gcw
ID: 1442441
DAO
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 150 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 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