Results 1 to 9 of 9

Thread: Query on the fly?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Query on the fly?

    Hi i want to create a query on the fly. Meaning i have a query that contains, name,class,group,attend,date.... What i want to do is select a certain date from this query and put them into another query(temperary if possible). can this be done.
    I'm using MS Access,VB6...

    Thanking you in advance
    Chris lynch
    11 is the magic number

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

    Re: Query on the fly?

    How are you connectiong to your db? ADO? You can create a query dynamically and pass that in an
    ADO Recordset .Open method call.
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: Query on the fly?

    Yes I'm using ADO sorry for not mentioning it..... HAve you an example of what you said or a link... Something to get started with?

    Thanks
    ChrisLynch
    11 is the magic number

  4. #4
    New Member
    Join Date
    Apr 2005
    Location
    Montréal, Québec
    Posts
    10

    Re: Query on the fly?

    Set your report database's datasource to a recordset.
    (Ex: Report.Database.SetDataSource YourRS)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: Query on the fly?

    where in vb6 and then this will do what?
    11 is the magic number

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

    Re: Query on the fly?

    Something like
    VB Code:
    1. Dim sSQL As String
    2. sSQL = "SELECT name,class,group,attend,date FROM yourtable "
    3. adoRs.Open sSQL, cnobject
    4.  
    5. 'then you could insert the results of your recordset into a temp
    6. 'table to which your crystal report was bound

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: Query on the fly?

    I'm using an access database, is that a problem?
    11 is the magic number

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

    Re: Query on the fly?

    Quote Originally Posted by chris lynch
    I'm using an access database, is that a problem?
    Nope...for years I worked on an application that used Oracle as the backend. With the code, we shipped an Access Database. This Access database had a boat load of tables in it, and each table had a Crystal Report bound to it.

    When I ran a SQL query against the Oracle database, I created a recordset and feed the recordset into the appropriate Access Table, and the bound Crystal Report resulted.

    Of course, prior to each run, the contents of the table was deleted before the new recordset data was inserted.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    133

    Re: Query on the fly?(Bumped)

    I have that done and it just runs throught the code and nothing happens.... Is there something else i'm missing?

    HI again, i have been gone awhile, i've been looking for some cod eto work with this....

    Have i got it right that the following code won't show anyresults. What can i do to show the recordset on a form?

    Please help please

    VB Code:
    1. Dim rs As New ADODB.Recordset
    2.         Dim myconn As New ADODB.Connection
    3.         Dim sql As String
    4.        
    5.         myconn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;Initial Catalog=D:\Documents and Settings\christopher.lynch\Desktop\Complete Manual program\Manualrecords.mdb;" & " Pwd= " & Txtpassword.Text & "  "
    6.    
    7.         myconn.Open 'connection string'
    8.  
    9.         sql = "SELECT * FROM [Total]"
    10.        
    11.         If Len(TxtManualdate.Text) > 0 Then
    12.        
    13.             sql = sql & " WHERE [Date] = #" & TxtManualdate.Text & "# "
    14.             Debug.Print sql
    15.            
    16.         End If
    17.        
    18.        
    19.                  rs.Open sql, myconn
    Last edited by chris lynch; May 5th, 2005 at 09:42 AM.
    11 is the magic number

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