Msgbox question

  • Thread starter rebecky via AccessMonster.com
  • Start date
R

rebecky via AccessMonster.com

This seems like such a simple, basic thing, but I cannot get it quite right.
I have an employer form(main form) with a position posting(subform). I have
added a "cut" command button and just want it to display a msgbox telling the
user that if he/she is in the main form, he/she must use the "cut" button on
THAT form........otherwise the error msgbox will say "Nothing to cut!"
What have I done wrong?


On Error GoTo Err_Command241_Click

Screen.PreviousControl.SetFocus
RunCommand acCmdCut


Exit_Command241_Click:
Exit Sub

Err_Command241_Click:
If Screen.ActiveForm.Name = "EmployerPositions1" Then

MsgBox "You Must Use the Employer Cut Button to Cut Employer Information"

Else

MsgBox "Nothing to Cut!"
End If

Resume Exit_Command241_Click

Exit Sub

End Sub
 
A

Albert D. Kallal

When they click on the cut button they are changing the focus to the main
form.

It seems that you should move the cut command AFTER you test for the
correct screen. You don't want to execute the cut command and then start
checking things.

Even more problem is when you click on that button, the focus changes, and
I think you may loose your selection anyway.

The other problem here is that a sub-form is NOT a real form, but only a
control with an **instance** of the sub-form. In other words, you can't test
that the focus is the sub form name, you can only check if the previous
control
was in fact the name of the sub-form control.

(you can have 5 forms open each with the same sub-form in it...which
sub-form one are you accessing???? So, you *always* will get back the
current parent form name).

dim ctPrevious as control

set ctPrevious = screen.PreviousContorl

The above lets you "grab" the previous control..and then if focus changes,
you can still work with the field name....

I would then check if the previous control was the sub-form

if ctPrevious.Name = "Name of subForm control" then

MsgBox "You Must Use the Employer Cut Button to Cut Employer
Information"

Else
' ok...cut
Screen.PreviousControl.SetFocus
RunCommand acCmdCut
end if

You have to test the above with a msgbox command (put it right after the set
ctPrevious) to see if the sub-form control name is returned. If the name of
the previous control in the sub-form is returned then this might become
quite difficult to do...

And, to make the cut/paste work, you likely will have to re-set the focus as
I did above.
 

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

Top