Solved

Display table via a click on a button...

Posted on 2003-12-08
11
299 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
 
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
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)

 
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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 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

20 Experts available now in Live!

Get 1:1 Help Now