Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View selected table within form?

Status
Not open for further replies.

WaltW

MIS
Joined
Jun 14, 2000
Messages
130
Location
US
Is there a simple way within an Access 97 form to enter/select a tablename in the current database (with a text or combo box), then once it's entered, open and display the contents of the selected table in another window or object on the same form?

Thanks for any help provided.

WaltW
 
I think I'd just use a subform to display whatever contents of the selected table you wish.

You should, I think, then be able to set the Record Source of the subform using code generated by your text or combo box and refresh to form to get it to display the table after the Record Source has been set. - - - -

Bryan
 
Thanks for the suggestion, Bryan, but could you give me an example of the type of code you'd use to do this? I haven't done much with handling of forms and subforms, so I'm not at all sure where to start with this. I just want to display all the fields in the selected table in a datasheet view, and was hoping not to have to handle every field in the table selected. Thanks!

Walt
 
if you create a combobox then one of the options in row source type is field list. so if you set the rowsource to your table and row source type to field list then you can choose your fields out of that list
"What a wonderfull world" - Louis armstrong
 
Thanks for the response, chrissie1, but are you sure your response was intended for this question? I'm trying to use the text (a table name) entered into a combo box to control which table is displayed in a subform on the same form. I've gotten as far as changing the Record Source of the subform to show the selected table, but I'm having trouble with changing the subform to display the specific fields and field names in the selected table (since field lists are generally different for each table).

Isn't there some way to have a subform just display a table in datasheet view? Without having to mess with each individual field?

Thanks.

Walt
 
Hi, the code below is meant just as a guide, paste this into the On Load event of your form:

Dim dbs As Database
Dim tdf As TableDef
Dim strTableName As String
Set dbs = CurrentDb
For Each tdf In dbs.TableDefs
If InStr(tdf.Name, "MSys") = 0 Then
strTableName = strTableName & tdf.Name & ";"
End If
Next
If Len(strTableName) > 2047 Then
Me!MyList.RowSource = ""
MsgBox "List is too long!"
Else
Me!MyList.RowSource = strTableName
End If
Set dbs = Nothing


Paste this into the Double Click event of your listox:

DoCmd.OpenTable Me!MyList

This routine will populate a listbox called MyList with all the tables in your current DB other than System Tables. Double clicking MyList will open the selected table for viewing.


 
Sorry for the late response . . the notification mail just showed up!

In my model, I suggested using a text box to populate a variable and then open the form using the input from that form. It goes something like this:

Design an unbound form (i.e. frmInputForm). Set the name of a text box to be used for input to a variable (i.e. strTableName).

Place a command button on the form which will open the main form (i.e. frmMainForm) and set the control source of the subform to the variable value obtained. The code behind the OnClick event of the Command Button should look something like this:

DoCmd.OpenForm "frmMyMainForm", 'arguments here
Forms!subMySubForm.RecordSource = Forms!frmInputForm.strTableName
- - - -

Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top