-
Nov 22nd, 2019, 09:43 AM
#1
Thread Starter
Addicted Member
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?
-
Nov 22nd, 2019, 12:14 PM
#2
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?
-
Nov 22nd, 2019, 12:17 PM
#3
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)?
-
Nov 22nd, 2019, 12:29 PM
#4
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
-
Nov 23rd, 2019, 06:12 PM
#5
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
-
Nov 24th, 2019, 02:23 PM
#6
Thread Starter
Addicted Member
-
Nov 25th, 2019, 06:57 AM
#7
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
-
Nov 25th, 2019, 11:10 AM
#8
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?
-
Nov 25th, 2019, 05:29 PM
#9
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
-
Nov 26th, 2019, 11:43 AM
#10
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|