Results 1 to 16 of 16

Thread: [RESOLVED] VB6 to MS Access 07 - ADO / datagrid.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Resolved [RESOLVED] VB6 to MS Access 07 - ADO / datagrid.

    Hello everyone,

    I am using an ADOdc object to connect to an MS Access 07 database from my VB6 program.

    In my first form, I add some data to a table in the database. In my second form, I then use an SQL query to search for the previously entered primary key (from the previous form), and only display records with that primary key in the datagrid.

    Unfortunately, the datagrid will not display the last created record (i.e. the most recent record, which was added in the previous form).

    The SQL query searched by a defined parameter "OrderID", which is taken from a text box on the form. If i set the text box to a number before compiling, instead of calling it from the previous form, the datagrid will display the correct record. Also, if i set the SQL query to display all records, it still will not show the most recent record.

    As I say in the code, the SQL query works just fine if i set the text box to a number of an existing record before i run the code, so I believe the problem is just to do with the most recent record for some reason.

    Sorry it's a long post, and any help would be massively appreciated. If it makes it easer for you to see the project itself, please ask.

    Thanks again, best wishes,

    Last edited by rainer; Apr 27th, 2009 at 08:17 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Welcome to VBForums

    I think you will find the answer in the "Classic VB - Data-bound controls" section of our Database Development FAQs/Tutorials (at the top of this forum).

    There are only two articles in that section, the second of which has the answer, and the first (which I would recommend reading) explains why there aren't more articles in that section.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Hello Si,

    Thanks very much for the information.

    Below my SQL query I added the ...recordset.requery command, but unfortunately I am still having the same issue.

    Again, the SQL works with an existing OrderID.

    New code:
    Code:
    Me.adoOrderBunch.RecordSource = (SQL query)
    
    Me.adoOrderBunch.Recordset.Requery
    Me.adoOrderBunch.Refresh
    Me.datOrderGrid.Refresh
    Any more ideas?

    Thanks again friend,

    Much appreciated!

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 to MS Access 07 - ADO / datagrid.

    OK, well in that case are you sure the record has actually been added to the database before this query runs?

    To check, open the table in Access when the code reaches that point.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Hello there,

    Yep I have opened the database after the previous form information is submitted and yes, the new record is there in the database.

    It's strange, the problem is only with the most recent record. If i set the Sql query to OrderID - 1 it will work for the record before.

    I have also tried using "Rebind" on the datagrid as opposed to the refresh method.

    Any more ideas?

    Thanks very much for your time Si, it's very helpful!

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Have you read and tried the suggestions in this FAQ article?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Hello there Dee,

    Yeah I read your comment and the others in that thread. I changed the code to rebind and still no success.

    This one's really bugging me now

    Thanks for your help so far guys,

    Any advice welcomed!

  8. #8
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Could you try it like this?
    Code:
    Me.adoOrderBunch.RecordSource = (SQL query)
    Me.adoOrderBunch.Recordset.Requery
    Me.adoOrderBunch.Refresh
    
    Set datOrderGrid.DataSource = adoOrderBunch
    Me.datOrderGrid.Refresh
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Hello Dee,

    With that combination I get "Object variable or with block variable not set" error at the "recordset.requery" line.

    If I put the refresh before the requery, no error but still the record is not displayed.

    Strange :S

    Thanks man, anything else you/anyone think I could try?

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    How about this?
    Code:
    Me.adoOrderBunch.RecordSource = (SQL query)
    Me.adoOrderBunch.Refresh
    Me.adoOrderBunch.Recordset.Requery
    
    Set datOrderGrid.DataSource = adoOrderBunch
    Me.datOrderGrid.Refresh
    Me.datOrderGrid.ReBind
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Same old chestnut, nothing displayed in my grid

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Could you post your project and tell us how we could replicate what you are doing?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Re: VB6 to MS Access 07 - ADO / datagrid.

    Okay then. Unzip Project.zip, open Bloom.vbp, and set startup to frmAddOrderCustomer if it is not already.

    Run the project, and first select a customer from the combo box (any customer is fine). In the second window, select a bunch and a quantity (there is no validation so ensure the quantity is numeric. Press add to order, and the form with the datagrid will appear, showing no results.

    The database is included so you can see the relationships etc.

    If you have any questions about any of it please ask.

    There are other forms in the project but these are just to add customers, bunches, orders etc. They are not relevant to this code. I am also yet to comment the code so if you cant work it out just ask.

    Thanks a lot guys, you've been very helpful.
    Last edited by si_the_geek; Feb 21st, 2009 at 12:37 PM. Reason: removed attachment (contains coursework)

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    The Load event of your frmAddOrder is already triggered when you are showing frmAddOrderCustomer so when you are showing it in your cmdAddItem_Click in frmAddOrderItem then its not being refreshed since the load event is not being called.

    One quick solution is to add this in your frmAddOrder
    Code:
    Public Sub RefreshRecord()
        Me.adoOrderBunch.RecordSource = "SELECT Bunch.[Bunch Name], Bunch.[Bunch Unit Price], OrderBunch.Quantity, [OrderBunch]![Quantity]*[Bunch]![Bunch Unit Price] AS SubTotal FROM Bunch INNER JOIN OrderBunch ON Bunch.[Bunch ID] = OrderBunch.[Bunch ID] where OrderBunch.[Order ID] like '" & OrderID & "%';"
        Me.adoOrderBunch.Refresh
        Me.adoOrderBunch.Recordset.Requery
        
        Set datOrderGrid.DataSource = adoOrderBunch
        Me.datOrderGrid.Refresh
        Me.datOrderGrid.ReBind
    End Sub
    then call it like
    Code:
    Private Sub cmdAddItem_Click()
    
    Me.adoBunchORder.Refresh
    Me.adoBunchORder.Recordset.AddNew
    Me.adoBunchORder.Recordset.Fields("Quantity") = Me.txtQuantity.Text
    Me.adoBunchORder.Recordset.Fields("Bunch ID") = Me.adoBunch.Recordset.Fields("Bunch ID")
    Me.adoBunchORder.Recordset.Fields("Order ID") = Me.txtOrderID.Text
    Me.adoBunchORder.Recordset.Update
    Me.adoBunchORder.Refresh
    
    Me.adoBunch.CommandType = adCmdTable
    Me.adoBunch.RecordSource = Bunch
    
    'Me.adoBunchORder.Recordset.Close
    'Me.adoBunch.Recordset.Close
    
    Unload Me
    frmAddOrder.Show
    frmAddOrder.RefreshRecord
    
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2009
    Posts
    8

    Thumbs up Re: VB6 to MS Access 07 - ADO / datagrid.

    Wow, Dee, that's worked a charm. I realise now that I called the form when sending the OrderID in the text box, oops!

    You've been very helpful, so thanks very much. It's much appreciated man!

    Best wishes,

    Rainer

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 to MS Access 07 - ADO / datagrid.

    No problem. Glad to be of help. You can now mark your thread as resolved.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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