473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Minimized form loses bind

10
Dear guys,
I am having problems minimizing and restoring forms. I am using Access 2003 on WXP.
In my DB I am using just unbound forms. The typical form has a main area with controls to edit new records or modifying existing ones, and a subform in datasheet view with all or part of the records in the related table.

On opening the form I bound both form and subform with the following function:
Function GeneralRequeryForm(CurrFormName As String, QueryConnName As String) As Boolean
Dim cn As ADODB.Connection
Dim rsmain As ADODB.Recordset
Dim frmActive As Form
Dim strsql

On Error GoTo Err_Handler
Set frmActive = Forms(CurrFormName)
Set cn = CurrentProject.AccessConnection
Set rsmain = New ADODB.Recordset
With rsmain
Set .ActiveConnection = cn
.CursorLocation = adUseClient
.Source = "exec " & QueryConnName
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
Set frmActive.Recordset = rsmain
Set frmActive![ThisSubForm].Form.Recordset = rsmain
GeneralRequeryForm = True
Set rsmain = Nothing
Set frmActive = Nothing
Exit Function
Err_Handler: Call LogError(Err.Number, Err.Description, CurrFormName, "GeneralRequeryForm", , True)
End Function

Everything works fine until I minimize the form. When I do it and thenafter I restore it, the form is still bound but the subform recordsource is null and therefore the control is blank. Of course any reference within the code to the subform gives back an error saying that the object referred by the instruction is closed.
It could be an idea reloading the subform and in case resynchronizing it with the main form, provided there was something like a restore event for the form which, to my knowledge, there is not.

I am sure this is a common problem encountered by other people before but at the moment I don't know the solution.
Have you any idea?
Thank you for any help you can give me.
Jacopo
Feb 4 '08 #1
5 2091
FishVal
2,653 Expert 2GB
Hi, Jacopo.

Actually the Recordset is being destroyed in your code before you minimize the form. Just when Form window needs to be repainted Access refreshes controls' values from Form.Recordset. I guess the same will be if you put the form window behind other window and then activate it again.

Concerning your code I would like to say that to my mind it is a bit overkill. Did you try to set Form.RecordSource property?
Expand|Select|Wrap|Line Numbers
  1. Forms(CurrFormName).RecordSource = "exec " & QueryConnName
  2.  
Regards,
Fish
Feb 4 '08 #2
Jacopo
10
Dear Fish,
thank you very much for your kind reply.

I think that the recordset is definitely not destroyed because, and maybe i wasn't clear in my explanation, the problem affects just the subform which loses its recordsource, not the controls in the form. I still can edit, save and delete records, and using the navigation buttons I browse with no problem the whole table. Just the subform control is a white box (not bound).
Also this doesn't happen as you thought when I lose focus going on a different form (or on another application for that matter). It happens just minimizing it.

About the suggestion on how binding the form, it is absolutely sensible and I know that my code looks uselessly convolute. Matter is that the line you suggest gives back the error 3129 "SQL instruction not valid". I think it is because the query is a stored one and not a SQL instruction. Stored query give a lot of problems, but have the advantage that when this program will be converted to SQL SERVER I won't need to go through the code changing the SQL statements to the proper dialect.

Thank you again for any further idea.
You suggestions made sense to me.
regards,
Jacopo
Feb 4 '08 #3
FishVal
2,653 Expert 2GB
Hi, Jacopo.

Its weird. I've tried a code similar to your's with no problem.
Main form: on Load event Form.Recordset changed to ADODB.Recordset having local query as a source
Subform: stays the same - DAO.Recordset.

Is your situation other?
Feb 4 '08 #4
Jacopo
10
Dear Fish,
again thank you. I fire the code in the on open event and not in the on load event but I don't think that that is the problem because on_open occurs later than on_load (but you tell me if I am wrong).
I am afraid I don't understand when you refer to a DAO.recordset for the subform.
There is no DAO at all (ok almost) in my DB. Just ADODB and I use the same ADODB recordset for both main and sub.

I made a tiny DB for you with all my modules and everything hoping I could attach it to the message so that you could try it but I can't.
Please let me know if there is a way to do it.
Thank you,
Jacopo
Attached Files
File Type: zip db1.zip (130.1 KB, 71 views)
Feb 4 '08 #5
FishVal
2,653 Expert 2GB
Ok. Having submitted a post click on [Edit/Delete], then click on [Manage attachments] button and attach the sample packed into zip or rar.
Feb 4 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized...
2
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized...
1
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized...
2
by: Carsten Klotz | last post by:
Hi, does someone know, if it's possible capturing the content of a panel, when its form has state "minimized"? Details: A panel contains a Webbrowser object (AxSHDocVw.AxWebBrowser). My...
2
by: Bruce W.1 | last post by:
There's something I can't figure out. I added some javascript behavior to my datagrid, just like in this article, except in C# instead of VB: ...
5
by: vooose | last post by:
Consider a Form with dimension Size=(300,300) that is then minimized. Subsequent calls to Size return (160,24). The Form is then restored and Size returns (300,300) Is there any property or...
2
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor...
6
by: =?Utf-8?B?QWxsZW4=?= | last post by:
When minimizing Visual Basic application, working memory is greatly reduced from about 20 MB to only about 2 MB. However I want the application to start as minimized, and most of the time it will...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
using WinXp (SP3), VB2005. sometimes when a user opens the app - the app opens in minimized WindowState and clicking on the app's icon in the windows taskbar wont open the app to Normal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.