Updating a field/control (1 Viewer)

Tim L

Registered User.
Local time
Today, 01:49
Joined
Sep 6, 2002
Messages
414
This is a problem of transferring text between two forms and getting a control to update, I've posted this here because I suspect that the answer lies in VBA and not the form...

I have a "comments" text box (memo field) on a form, which is locked. Operators are allowed to add more comments, but for each comment the current date and time are to be included, and are added automatically. To (try and) keep things simple, when the operator clicks on an Add Comments button a pop-up form opens and (using OpenArgs) is passed the current comment.

The operator types in their additional comments, can preview the changes and cancel the operation if they are not happy. If they are happy with the modified comments they click on a 'Transfer' button, this is where the fun begins...

Currently I have a global string, globalStrComment, into which I copy the updated comment. I then have to then get the operator to click on a control on the form to update the value, it won't work in the OnActivate or GotFocus events :( I want things to be automatic because if the operator moves away from the form before clicking on the control the field is not updated.

I thought about using a Function to get the updated comment (, call func with textbox.value, open the form passing original comment, While-End until the form closes, updating the global string in the process, then return the value global string from the function) however this just, I suppose unsurprisingly, causes the program to hang.

So,

1) How can I get the field on the calling form to update as soon as the Add Comments form is closed (I may wish to reuse the add comments form elsewhere) ? and,
2) How can I get the visible contents of the control to be updated automatically and at the same time?

This one is proving a challenge to me but I'm fairly certain that someone out there must have done something similar, so are there any other suggestions?

Yours, in anticipation,

Tim
 

Mile-O

Back once again...
Local time
Today, 01:49
Joined
Dec 10, 2002
Messages
11,316
Tim L said:
How can I get the field on the calling form to update as soon as the Add Comments form is closed (I may wish to reuse the add comments form elsewhere) ?

You are using the wrong events. Activate is wrong because, as the help files say, "the Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form" and the Got Focus is wrong because a form only gets the focus when there is no control on that form capable of receiving the focus. So, what to do? Use the Close event of the other form.

I suggest you study how events are triggered. The help files are very detailed in this respect.
 

Tim L

Registered User.
Local time
Today, 01:49
Joined
Sep 6, 2002
Messages
414
SJ, thanks,

Had a good look in help, found the most useful information at "Order of events for database objects".

Okay, so I can, if I set Pop Up to No, use OnActivate, and hey, update problem solved. But wait, if I set Pop Up to No then the (little) comments form automatically maximizes, because the previously opened form was. So, how do I prevent the comment form from maximizing itself, without setting Pop Up to Yes?

I've tried the suggestions at: http://www.access-programmers.co.uk/forums/showthread.php?t=44658 to no avail. Once I have opened the comment form (which maximizes) the calling form resets itself to un-maximized when the comment form is closed, thereafter the comment form appears as I wish it to, looking like a pop-up, but the calling form is all wrong and needs to be re-maximized, which maximizes the comment form again... - it's a never ending circle :(

Alternative; leave Pop Up at Yes and find a way to transfer the text from the OnClose event of the comment form. The problem here is determining how to reference any form? So, I can pass the calling form name to the comment form, in OpenArgs and extract it, but I would not know how to use the information, which is now text (yes?); I don't want to hard code form names in so that I can re-use the add comment form. I'm presuming here that there is some way of creating an object reference to the originating form, but this is way out of my league.

Final hypothesis; going back to a Function, is it possible to prevent a Function from executing past a certain point without causing the system to hang? For example, to open a form and to wait until the form has closed until proceeding in execution. Or to be able to return a value from a public proc, in the manner of a function?

Yes, I suppose it does look like I'm trying to find ways around the problem rather than through it, but I'm treading water here... and sinking, so looking for anything to hang on to :)

Tim
 

pono1

Registered User.
Local time
Yesterday, 17:49
Joined
Jun 23, 2002
Messages
1,186
Tim L said:
...is it possible to prevent a Function from executing past a certain point without causing the system to hang? For example, to open a form and to wait until the form has closed until proceeding in execution...
Tim
Yes, it is possible.


Code:
Dim MyVariable as String

'Open form and wait...
   DoCmd.OpenForm "FormName",,,,acDialog

'Waiting...

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Code to execute after the form just opened is made *invisible*
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Fetch the value on the form
   MyVariable = Forms!FormName.TextBoxName.Value

'Close the form because we've saved the value 
'from one of its textboxes into a local variable.
  DoCmd.close acform, "FormName"

'Do something with MyVariable
   msgbox MyVariable

Regards,
Tim
 
Last edited:

Tim L

Registered User.
Local time
Today, 01:49
Joined
Sep 6, 2002
Messages
414
pono1 said:
Code:
'Open form and wait...
   DoCmd.OpenForm "FormName",,,,[B]acDialog[/B]
This is just what I needed! Grrr, isn't everything *so* simple when you know how! :D

Because of the way I use a global variable to store the comment I don't need to close the form from within the Function (and couldn't figure out how to determine when the operator had completed their actions from within the function anyway); the function just waits until the form closes, captures the global variable and returns that.

The help file is not very helpful :rolleyes: about acDialog as all it says is the form is opened with it's Pop Up and Modal properties set to Yes, and not that execution of the routine opening the form will halt until the form is closed; implied knowledge I suppose, but this wouldn't work with the Pop Up and Modal properties set to yes in the form and acDialog ommited from the DoCmd.OpenForm instruction, so it's hardly intuitive.

Much grateful, many thanks. :)

Tim
 

pono1

Registered User.
Local time
Yesterday, 17:49
Joined
Jun 23, 2002
Messages
1,186
Glad to have helped, Tim.

Regards,
Tim
 

Users who are viewing this thread

Top Bottom