Results 1 to 8 of 8

Thread: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Question Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    Hello everybody,
    How do we create a query in runtime from VB6 and save it to an existing database (Access 2003)

    Thankyou

  2. #2
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    Before trying to create a query you need to specify what type of queries you are going to allow. And you must describe the scenario. If you are trying to just write a query in a text box, then you only have to save it to the Database. But if you are going to build it with given keywords and/or if you want to specify what is the database and what are the tables/columns, then you'll have to design an interface and do the codings.
    If the post is heplful, Please Rate it
    Chathura Wijekoon

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    You would need to save the query to a string and save the string to your database as text.

    I have done similiar things, but save them to an external text file. The one big problem with this is that you have no variables in them. The query will be saved as literal values so if it contains dates, the date won't change.

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    I don't have the exact syntax at hand, but back in the day, I used DAO within the VB app to create a QueryDef object in the Access database, for subsequent use in a Crystal Report. You could still use DAO objects, or the ADO equivalent, to create or modify a query in an Access database. The main point is, you would typically do so for the purpose of immediately subsequently using the query as the basis for a report. (I mentioned Crystal Reports, but you could also apply the same idea if you wanted to run an Access report from your VB app, and the standard way of doing so, i.e. the "DoCmd" to run the report with a "where" clause created dynamically was not quite adequate for your needs.)
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    What I do is to execute a sql statement that will create the query in the acccess db. Then call the query passing any parameters in a command object.

    Use the CREATE VIEW syntax for your sql statement and execute off of your ADO connection object.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    Use the CREATE VIEW syntax for your sql statement and execute off of your ADO connection object.
    Yes I have something like that in mind. But the Problem is I neither know the syntax/procedure to accomplish the feat nor aware of the references that I may have to add to the proj to accomplish this. I would be happy if you could give me a small example.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    Sure, use ADO (tutorial in the DB forum FAQ, and from your connection object...

    Something like so:
    oConn.Execute "CREATE VIEW qryVBF AS SELECT Field1, Field2, Field3 FROM Table1;"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Create a Query from VB6 and store it in DB (Acs 2003) - Runtime

    I tried to run the below code
    Code:
    conn.Execute "CREATE VIEW QryFromVB AS SELECT fName, mName, lName, DOB From CounselMaster ORDER BY fName;"
    I got error Only simple SELECT queries are allowed in VIEWS what does this mean how do I make a query which has sorted data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width