Is it possible to pass the focus?

B

BruceM

Is it possible to have a command button on a form (frmMain) open an unbound
form, then for an event on the unbound form (a command buton click event,
for instance) pass the focus back to a control on frmMain? The unbound form
is neither pop-up nor modal.
I could provide more details, but I have already asked this question twice
in some detail without any response, so I am keeping it short this time.
Maybe I had too much detail before. I have to assume it is impossible to
pass the focus back to the main form, but does anybody know for sure?
 
S

Sprinks

Hi, Bruce.

Use the OpenForm method to return to the original form, and the SetFocus
method to go to a specific control:


Dim stDocName As String
Dim stLinkCriteria As String

' Close current form (optional)
DoCmd.Close

stDocName = "YourOriginalForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!YourOriginalForm!YourControl.SetFocus

Hope that helps.
Sprinks
 
K

Klatuu

Yes.
In the Click Even of frmMain:
DoCmd.OpenForm "MyUnBoundForm"

In the Click event of th button on the unbound form:
forms!frmMain!SomeControl.SetFocus
DoCmd.Close 'Will close the unbound form.
 
B

BruceM

Thanks to both for the suggestions. As it happens I am done for the day,
and will be away until Monday, so I won't be able to report back on my
progress until then, but I want to extend my appreciation for the replies.
More to come.
 
B

BruceM

I asked the question in the briefest possible terms, since previous
questions had gone unanswered. I see that I did not provide enough detail
this time.
I have a form for producing a report (in the generic sense of the term
"report", not the Access object). Each report may have links to several
supporting documents. Each one of these links is a separate subform record.
I am using a hyperlink field on the subform for adding links to locations on
our network. It works well enough, but it will be necessary to add the
links in what I think is called UNC format (in other words, using the full
network path rather than mapped drive letters, which are not consisitent
from computer to computer. Not everybody will know how to use the Insert
Hyperlink dialog box, so I am trying to provide instructions. That is the
purpose of the unbound form.
Here's the general setup: The user click a command button to add a link to
a file. An unbound form appears, containing instructions for drilling down
through the network to insert the link. I would like the unbound form to
remain visible along with the Insert Hyperlink dialog box. However, in
order for the Insert Hyperlink dialog box to appear I need to have the focus
in a control bound to a hyperlink field. This is where the difficulty
arises. I cannot pass the focus to that field (by way of the bound control)
while the unbound form is open. I tried the code you suggested. While I
can see the value of the approach, and understand a few things better than I
did previously, in this case what I get is an extra instance of the subform
by itself.
In the meantime I have been working my way toward another solution. I have
created a table (tblLink) with a single hyperlink field, and have bound the
previously unbound form (the one with the instructions, which I will call
frmInsertLink) to that table. To frmInsertLink I have added a text box
bound to the hyperlink field in tblLink. After navigating to the link
(using the Insert Hyperlink dialog box) a command button copies the
hyperlink to the appropriate field on the subform, then closes
frmInsertLink. The next time frmInsertLink is opened the field is cleared.
Am I missing something in your suggestion, or was I remiss in not specifying
that I needed to pass the focus to a subform control? Can I use your
approach to open the main form instead, then navigate to the subform? The
main form has four tab controls (for different sections of the report).
Different tabs will have different subforms. Would this present
difficulties in passing the focus to a particular subform, then the
appropriate control on that subform?
At this point I think my approach of passing the hyperlink from
frmInsertLink is a workable approach, but I can't help wondering if I am
making this more complex than it needs to be.
 
Top