Need to eliminate hard coding.

  • Thread starter Thread starter ortaias
  • Start date Start date
O

ortaias

The following line works, as hard code. The variable "CallingForm"
holds the name of the form that activated a second form. The "hard
code" is the refrence to "pending4frm" in
"Forms![pending4frm].SetFocus"

If Not IsNull(CallingForm.Value) Then Forms![pending4frm].SetFocus

The problem with the code above is that it is tied to a specific form
"pending4frm"; it needs to be adaptable. I tried the code below, but
that did not work.

formname = "Forms!" & [CallingForm] & ".setfocus"
Not IsNull(CallingForm.Value) Then formname

I also tried the code below, and that did not work either

With CallingForm
If Not IsNull(CallingForm.Value) Then .SetFocus
End With

Any solutions?
 
Provided the form is not a subform, you could call the form by name like
this:
Forms(CallingForm).SetFocus

I didn't follow the IsNull() test though: the form doesn't have a value.
 
Allen said:
I didn't follow the IsNull() test though: the form doesn't have a value.

"CallingForm" is a text box, the null test is used to determine if the
form was opened by another form. If the value of "CallingForm" is null
then there is no need to run the code. However, if "CallingForm" is
not null, then the program needs to know the name of form (contained in
the CallingForm text box) that called it to update that form and return
the user to that form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top