Get values from one form to another...

buratti

Registered User.
Local time
Today, 01:41
Joined
Jul 8, 2009
Messages
234
I have several situations where I need to get data entered on form2 into form1 where form2 is an unboud form. For example, I have situations where a simple msgbox() function will not suit my needs so I created some so called custom "message box forms". (situations like I need to change the lables of the buttons from Yes/No to whatever is revelant to what is calling the message box, or need to choose a value from a listbox on that msgbox form and enter it into a field on the calling form, etc.)

Essentially the Msgbox() function is just a function that returns a value back to the line of code that called it. How do I go about getting my custom message box form to return a value back to the line of code that opened it just like the msgbox function does?
 
You can use RecordSet or Append query linked to your controls on the Custom Message Box and on the Yes button or OK button you can put the Code which will run the RecordSet or the Append query and update your previous Form data on its table or any other table or controls you might select in your code,
working with custom messages box is fun and easy but you need lots of logic,
regarding changing the buttons names as per your needs you can set the code on the after updates events on your combo boxes to change the caption of your button as per your executed code.
hope you got a proper help.
 
Ok, so what I am understanding your response as is... I have some action on my main form that triggers the open of my message box form. I select the apropiate answer on my message box form and, lets say the onClick of the "Yes" answer I attach an update query that updates the record of the table my main form is based on?

I do not have a working example of this whole custom message box thing to test it out on. This question is more of a what if/future reference scenario. But with your suggestion I forsee two possible problems with it...

First problem is, I have a similar situation where my form calls a public function on a module which essentially runs some calculatoins and uses an update query to enter those calculations into the same record in the form that called the function. This is essentially the same thing that you are suggesting to do with the custom message box form/code, correct? The problem I have with this is when I return back to my original form and then try to close it, I get a warning "This record has been updated by another user..." or something llike that and asks me to save or drop changes. Because the record is being updated from two different sources at the same time, I can see why I am getting that message. Would that not be the same case with your suggestion?

My second problem is, what if I dont need to update a record with the message box, but rather return a "true/false" or "yes/no" value to be used in an If statement? For example, with the regualr msgbox () function I would do someting like:
Code:
If msgbox ("Do you want to continue", vbYesNo) = vbYes then
'do something here
End if
If I wanted to replace msgbox() with the opening of my custom message box form and return a value from it, how would I restructure that simple statement above?
 

Users who are viewing this thread

Back
Top Bottom