How to change query table name at run time in crystal report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irfanafzal
    New Member
    • May 2010
    • 12

    #1

    How to change query table name at run time in crystal report

    Hello
    I have saved query in MS Access
    "SELECT ID ,Name, Address from Data2001"
    I am using this query in Crystal report
    My question is this can I change table name in this query "DATA2001" to "DATA2002" at runtime
    Thanks .
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    What is your version of CR..?

    Comment

    • irfanafzal
      New Member
      • May 2010
      • 12

      #3
      Sir i have CR 9

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        After Opening report (CrRep), write this code:

        [code=vb]
        Dim crDB As CRAXDRT.Databas e
        Dim crTab As CRAXDRT.Databas eTable
        ' Open Cr appl and report here..
        Set CrRep = CrApp.OpenRepor t("C:\MyReport. rpt")
        Set crDB = CrRep.Database
        For Each CrTab In CrDB.Tables
        crTab.Location = "C:\MyDB.md b"
        Next
        ' Code to show the report in cr viewer here...
        [/code]

        Regards
        Veena

        Comment

        • irfanafzal
          New Member
          • May 2010
          • 12

          #5
          VERY VERY THANKS FOR REPLY
          I THINK I HAVE NOT GIVE U COMPLETE DETAILS.

          I HAVE SAVED QUERY (name of the query is "Details") IN ACCESS 2007.
          this query have the text "SELECT ID ,Name, Address from Data2001"
          (in this query there are also many other fields")
          now i want to replace the table name " Data2001 ' to "Data2002" in query text .

          i have 10 tables names Data2001,Data20 02..... and so on. all the tables have same structure
          (I want to change Table Name in Query Text Not table )
          i hope now you have understand my question waht i want.
          i want to use same query for all tables.

          is it possible ?

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            In that case simply Drop The QueryDef, and create a new with required table name... keep query name same

            Regards
            Veena

            Comment

            • irfanafzal
              New Member
              • May 2010
              • 12

              #7
              plz tell me how?
              how can i use queryDef.
              i am using ADO.
              with best regards

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Hi,

                CheckThis

                Regards
                Veena

                Comment

                • irfanafzal
                  New Member
                  • May 2010
                  • 12

                  #9
                  Hi
                  Thanks veena g. i think i have got my answer.

                  Dim cat As New ADOX.Catalog
                  Dim cmd As New ADODB.Command
                  Dim sqltext As String
                  ' create the sqltext as in the example above

                  Set cat.ActiveConne ction = CurrentProject. Connection
                  cmd.CommandText sqltext
                  Cat.Views.Appen d "My_Query", cmd

                  one thing more can i do the same thing without using ADOX.Catalog.
                  (I am using VB6) is it possible ?.Because some on told me it Create problems.(ADOX. Catalog)

                  Thanks Again
                  with best regards

                  Comment

                  • QVeen72
                    Recognized Expert Top Contributor
                    • Oct 2006
                    • 1445

                    #10
                    What kind of problems...?

                    Comment

                    • irfanafzal
                      New Member
                      • May 2010
                      • 12

                      #11
                      i dont know what type of problems creates this ADOX.Catalog'
                      some one told me that there are problems.(like some time u can not create quires or invalid connection like this).
                      i did not use this.
                      now i will use this for my project

                      thanks for helping me
                      with best regards

                      Comment

                      Working...