?
Solved

Display table via a click on a button...

Posted on 2003-12-08
11
Medium Priority
?
338 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
[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
  • 5
  • 3
  • 3
11 Comments
 
LVL 4

Expert Comment

by:dasari
ID: 9902362
Well, U can use ADO to do that......
0
 
LVL 34

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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 10

Accepted Solution

by:
jobrienct earned 2000 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 34

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 34

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

Industry Leaders: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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