Results 1 to 10 of 10

Thread: When should I lock/unlock, hide or unhide columns in DataGrid?

  1. #1

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    When should I lock/unlock, hide or unhide columns in DataGrid?

    I am working on an old VB6 application. Clearly no maintenance was held and the most of the code is placed in one form which has like 5000 lines. This is makes quite hard to find bugs.

    I can see that the DataGrid is the main part of the form and the code contains some logic for locking/unlocking and hiding/hiding columns when a certain condition is met.

    This data grid is connected to a predefined ADODC(placed on the same form) component which uses string query to load data from a table.

    Also when this form loads there are additional two queries that should fill the ADODC component on form load.
    I found that at some case the ADODC is with zero rows since the query doesn't find any data for the given case, but logic for locking/unlocking and hiding/hiding is still executed even there are no data to display in the DataGrid.
    This causes application failure with error

    Code:
    "datagrid runtime error "6160" Data Access Error"
    I tried to add some validation with the ADODC component like:

    Code:
    if MyAdodc.Recordset.RecordCount > 0 then
         ' do left over application stuff
    else
         Exit sub
    end if
    This however ended with another DataGrid control error:

    Code:
     The current row is not available.
    Is there something I should follow when using DataGrid and ADODC or this is simply a bad programming and badly designed flow of control?

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Actually, having only one form makes it EASIER (per se) to find bugs.

    Odd....this error is not received otherwise?

    Does your subroutine call another sub BEFORE your new IF statement? If so, then whatever would normally have been done if there were no records, still tries to execute.

    What is the line on which your error occurs? In what sub is that line included?

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Is it at all possible for you to create a dummy database and set your ADODC control to it, and then zip and attach the project (less the current database and any executables)?

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Which line caused the new error? Is it: if MyAdodc.Recordset.RecordCount > 0 then

    Else, it is always helpful to us if you provide the exact line that caused the error

    There are some typical checks that can be made:
    1. If MyAdodc.RecordSet Is Nothing Then ' no recordset was created/returned
    2. If MyAdodc.RecordSet.EOF = True And MyAdodc.RecordSet.BOF = True Then ' no records in the recordset
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    maybe you could do a count query first, if 0 don't execute the select query?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Hmm, I made some code to reproduce how the actual application works. It is similar but I get different error message now.

    Basically two forms are in the scenario. One is the main form and the second form is where you display the DataGrid component and load data into ADODC component.

    Main form:
    Name:  Adodc_DataGrid_Sample1.jpg
Views: 356
Size:  26.2 KB

    DataGrid form:
    Attachment 172525
    Name:  Adodc_DataGrid_Sample4.jpg
Views: 431
Size:  22.4 KB
    Name:  Adodc_DataGrid_Sample5.jpg
Views: 355
Size:  22.6 KB

    If you check closely the commented out line in the DataGrid Form onLoad event method, when I un-comment it, it fails with error message:

    Name:  Adodc_DataGrid_Sample6.jpg
Views: 379
Size:  10.0 KB

    I get data access error in the actual application.
    Is this the right way to work with ADODC and DataGrid? I mean modifying cell properties on the go and changing its data also on the go?

    Should I remove ADODC and work with RecordSet instead?
    Attached Images Attached Images  
    Last edited by kutlesh; Nov 24th, 2019 at 02:31 PM.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    I'm no DataGrid user. I would check the value of DataGrid1.Columns.Count. I would also check the recordset for being empty. In addition, recommend not returning all fields (i.e., Select * From ...) if you don't need all fields.

    Per MSDN
    *Note* If you set any of the DataGrid column properties at design time, you will need to set all of them in order to maintain the current settings.
    Documentation: https://docs.microsoft.com/en-us/pre...ectedfrom=MSDN
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    The DataGrid doesn't have a problem with an empty query. I wonder if you have an older version that isn't patched up to SP6?

  9. #9
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,126

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Should I remove ADODC and work with RecordSet instead?
    "I" would. Like LaVolpe, I am not a user of VB6's datagrid. To ME, it is less flexible (but others may disagree). When I work with recordsets, I KNOW what my data is when returned (easy to check).

    I did NOT look at your error, but simply added MY opinion (we all have those) on your question above.

    Sam

  10. #10

    Thread Starter
    Addicted Member kutlesh's Avatar
    Join Date
    Jun 2018
    Location
    Skopje, Macedonia
    Posts
    202

    Re: When should I lock/unlock, hide or unhide columns in DataGrid?

    Hmm, it might be yes. But only one OCX component circles around and its called MSDATGRD.OCX.

    Also could faulty installation be the problem when using the application itself?

    Only when Windows 7 is freshly restarted, the installation of VB6 app package gets installed without problem.

    When i uninstall and install the app again, I get warning messages that MSDATGRD.OCX, MSFLXGRD.OCX, MSADODC.OCX are occupied by some process as if previous installation doesn't clean references to these files.

Tags for this Thread

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