Solved

Display table via a click on a button...

Posted on 2003-12-08
11
310 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
ID: 9902362
Well, U can use ADO to do that......
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 9902366
Code is what I need.
0
 
LVL 4

Expert Comment

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

0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 10

Accepted Solution

by:
jobrienct earned 500 total points
ID: 9902386
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
ID: 9902387
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
 
LVL 10

Expert Comment

by:jobrienct
ID: 9902392
oh, I just noitced you said preview mode,

DoCmd.OpenTable "TblName", acViewPreview

John
0
 
LVL 4

Expert Comment

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

Expert Comment

by:dasari
ID: 9902439
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
ID: 9902505
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
ID: 9902533
0
 
LVL 10

Expert Comment

by:jobrienct
ID: 9902570
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

803 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