Solved

Display table via a click on a button...

Posted on 2003-12-08
11
288 Views
Last Modified: 2006-11-17
Without letting admin/user go to database window, I want table to be selected from a list box and viewed via a click on PreviewTable button (list box and button are done).

As you know RunSQL wouldn't work for Select queries.  Do you know how to display a table directly from a form?

Dim sqlStr As String                     \
sqlStr = "Select * From site"         |   this wouldn't work
DoCmd.RunSQL sqlStr                  /

Teach me how it is done.

Thanks,

Mike
0
Comment
Question by:Mike Eghtebas
  • 5
  • 3
  • 3
11 Comments
 
LVL 4

Expert Comment

by:dasari
Comment Utility
Well, U can use ADO to do that......
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Code is what I need.
0
 
LVL 4

Expert Comment

by:dasari
Comment Utility
Where do u want to view the data of the table....., I mean some kinda report or user defined form?

0
 
LVL 10

Accepted Solution

by:
jobrienct earned 500 total points
Comment Utility
hi Mike :)

Do you mean open the table in Normal view?

DoCmd.OpenTable "Employees", acViewNormal, acEdit


from the help...

  acViewDesign
acViewNormal (default)
acViewPreview

  acViewNormal opens the table in Datasheet view.
  If you leave this argument blank, the default constant
(acViewNormal) is assumed.

datamode One of the following intrinsic constants:
  acAdd
acEdit (default)
acReadOnly
  If you leave this argument blank, the default constant (acEdit) is assumed.


regards,

John
0
 
LVL 4

Expert Comment

by:dasari
Comment Utility
Dim adoCN As New ADODB.Connection
Dim adoRS As New ADODB.Recordset
Dim strTableName as String
Dim strSQL as String

adoCN.ConnectionString = CurrentProject.Connection
adoCN.Open

strSQL = "SELECT * FROM " & strTableName

adoRS.Open strSQL, adoCN, adOpenDynamic, adLockOptimistic

Do While adoRS.EOF = False
    Debug.Print adoRS(0)  'Prints the first Field value
    Debug.Print adoRS(1)  'Prints the second Field value
    'etc etc
    adoRS.MoveNext
Loop

Set adoRS = Nothing
Set adoCN = Nothing

'Don't forget to set a reference to "Microsoft ActiveX Data Objects 2.7 Library" or which ever version is the latest  on your PC.......
'Assuming strTableName holds the table name selected from the list box
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 10

Expert Comment

by:jobrienct
Comment Utility
oh, I just noitced you said preview mode,

DoCmd.OpenTable "TblName", acViewPreview

John
0
 
LVL 4

Expert Comment

by:dasari
Comment Utility
sorry for the doubling's; refreshed the window again........
0
 
LVL 4

Expert Comment

by:dasari
Comment Utility
Well, I thought I pasted my comment twice....never mind.....

The Row Source Property of the list box will contain the following query to show list of user tables available in the current database......

SELECT MSysObjects.Id, MSysObjects.Name FROM MSysObjects WHERE Type=1 And Flags=0 ORDER BY Name;
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Thank you John,

My overworked mind couldn't figure that.  I appreciate the time.
---------
Hi dasari,

I will post your points shortly.

Regards,

Mike
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
0
 
LVL 10

Expert Comment

by:jobrienct
Comment Utility
My pleasure Mike, glad I could help kickstart you.. now for a bit of sleep :-)

considering how simple that was it barely seems reasonable to take 500pts for it, but I don't have any change on me! :-o

Gnite,

John
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

763 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

15 Experts available now in Live!

Get 1:1 Help Now