How to display data from a table using parameter as table name?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramakanth05
    New Member
    • Jun 2007
    • 1

    How to display data from a table using parameter as table name?

    Hi,

    I have a problem pulling data from a table using the parameter as table name.

    I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given.

    If tbl2 is given in the parameter, I want all the records from tbl2 to be displayed.

    If anyone have any idea about this please help me out.

    Thanks,
    Rama Kanth
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Originally posted by ramakanth05
    Hi,

    I have a problem pulling data from a table using the parameter as table name.

    I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given.

    If tbl2 is given in the parameter, I want all the records from tbl2 to be displayed.

    If anyone have any idea about this please help me out.

    Thanks,
    Rama Kanth
    How/where are the table records being displayed and how is the table parameter being selected/specified ?


    MTB

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I'm afraid you're going to have to be a good deal clearer about exactly what you're trying to do here! Where are you entering/selecting this parameter? How do you want the information displayed; in a form, in a query? Are all these tables set up identically, i.e. do they have all the same fields, with only their data being different?

      If the tables' structure are the same, and you want to display them using a single form, you can design your form as you want, using one of the tables as the RecordSource, then delete the RecordSource in Design View. Then, in the Form_Open event you can assign the parameter (table name) to the RecordSource like this:

      [CODE=vb]Private Sub Form_Open(Cance l As Integer)
      strRecordSource = YourParameter
      Me.RecordSource = strRecordSource
      End Sub[/CODE]

      Good Luck!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by ramakanth05
        Hi,

        I have a problem pulling data from a table using the parameter as table name.

        I have three tables tbl1, tbl2, tbl3 and I want all the records of the table based on the parameter given.

        If tbl2 is given in the parameter, I want all the records from tbl2 to be displayed.

        If anyone have any idea about this please help me out.

        Thanks,
        Rama Kanth
        Pass the Table Name as an Argument to a Sub-Routine:
        [CODE=vb]Public Sub OpenTheTable(st rTableName As String)
        DoCmd.OpenTable strTableName, acViewNormal, acReadOnly
        End Sub[/CODE]
        To Open a specific Table pass its Name to the Routine:
        [CODE=vb]Call OpenTheTable("t blYourTableName ")[/CODE]

        Comment

        Working...