Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form, Set properties & Pause code 1

Status
Not open for further replies.

gallas

Technical User
Feb 5, 2002
55
GB
I wonder if anyone can help? With some forms I am using the open acDialog parameter to stop the code running whilst on the form, then when closing the form there is code to requery a control on the original form and this works fine.

However, I now have a scenario where I want to open one form from different forms and in different states eg.

This code runs from a button on subform QuotesSubform which is in a tab control on form CompaniesForm

stDocName = "QuotesForm"

DoCmd.OpenForm stDocName, , , , acFormAdd

Forms!QuotesForm.Form!CompanyID.DefaultValue _
= [Forms]![CompaniesForm]![CompanyID]
Forms!QuotesForm.Form.Modal = True
Forms!QuotesForm.Form!JobNumber.SetFocus

Now in this scenario I cannot use the acDialog parameter because I want to feed some properties/values to the form so that it opens as I want. The problem is I want to requery the original form. In the above case I would use the following code to run after update or on close of the form:

Forms!CompaniesForm!Quotessubform.Requery

If I put it in the form after update event it will only work if QuotesForm was opened from Quotessubform for example. But if opened from another form I would need different after update code to run.

Quotessubform is a continuous form with no edits, filters, additions, deletions allowed. I mention this because I've been playing with GotFocus and on Enter events to run the requery but without joy.

One alternative is to create lots of forms that open with the initial settings and close events that I want - but they would be difficult to administer.

Any ideas?

Thanks in advance. G. %-)


"If a job's worth doing, it's worth doing twice!"
 
Can you package these settings/parameters into the OpenArgs and get the form to respond appropriatly depending on the OpenArgs contents ?


I have forms that will act like DataEntry, View Only, Edit and Update - even getting data from different sources - depending on the value of the OpenAgrs value which is interpreted in the form's On_Open or On_Load events



'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Tks LS, I did look at OpenArgs but couldn't work out how to use it. If it can do what you say it would be ideal. Could you give me a simple example with a couple of form properties that I could work (learn %-) ) from? That would be much appreciated. G.

"If a job's worth doing, it's worth doing twice!"
 
OpenArgs is a text string. and as such can contain what ever you like

I have just been working on a case where I open a pop-up form that is bound to a table on the Many end of a 1-many relationship

Sometimes the form needs to open to add a new record, other times to edit an existing record.
If Edit Existing I need to pass in the RecordId
IF NEW then the RecordId will be Null but I need to pass in the Foreign Key that links this record to the table at the 1 end.

So I open the form with OpenArgs = RecordId & " : " & ForeignRef
( Setting RecordId = 0 to signal NEW record )

Then in this form's On_Load event
If Left(OpenArgs,1) = 0 Then
' This is a NEW Record
txtForeignKey = Mid(OpenArgs, Instr(OpenArgs,": ") + 2)
' Above extracts ForeignRef and puts it in text box control on the new form

'rest of code etc.

Else
LoadForm(Left(OpenArgs,Instr(OpenArgs," :")-1)

End If



This is dummy code to show you the principle.
More error checking is needed in canse the OpenArgs has been set up wrong by the sender etc

But basically you can concatenate as many things together as you want. You just need to disect then in the OnLoad event in the form.

If you get beyond a couple of parameters it might be well worth considering just defining Global variables that can be set before the form is opened and then read inside the form. This, at least, controls your data type and formatting better. All the usual caveats about managing global variables apply then of course.


'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 

Tks LS, works perfectly and so elegant!
My implementation is much simpler. All I need in the OpenArgs is a number which the form on load event evaluates using an "If Then Else" procedure to load the correct form properties, etc.

G. [thumbsup]

"If a job's worth doing, it's worth doing twice!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top