Solved

Simple SQL Question

Posted on 1998-10-29
9
127 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
 

Author Comment

by:gcw
ID: 1442441
DAO
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now