Solved

Simple SQL Question

Posted on 1998-10-29
9
134 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 7 hours left to enroll

635 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