Runtime Error 2450

M

macejsc

I'm at my wit's end here and cannot figure this out. I get a Runtime Error
2450 when I reference the subform one way a error that the object cannot be
referenced that way comes up. Here's my VB code.
****************************************************************************************************************
Private Sub Date_AfterUpdate()
VDATE = 0
[Date].SetFocus
VDATE = [Date].Text
[EXPDate].SetFocus
[EXPDate] = DateAdd("yyyy", 2, VDATE)
Forms![Student Info New Records]![Assisting Instructor Subform].SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].[Date].
SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].[Date] =
VDATE
End Sub
******************************************************************************************************************

The part as follows is what is giving me trouble:
Forms![Student Info New Records]![Assisting Instructor Subform].SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].[Date].
SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].[Date] =
VDATE

I want to reference the [Date] to where what is entered as [Date] in the
mainform is copied to the [Date] field in the subform. This way when people
enter in the data they don't have to enter it three or four times. (FYI The
EXPDate is the expiration date for a 2 year certification). I know after
reading somethings on here that I have to reference the subfrom through the
main form, but how can I reference one of the data fields within the subform??
I'm totally confused now, and don't really know where to go from there.
 
A

Allen Browne

Try:
Forms![Student Info New Records]![Assisting Instructor
Subform].Form![Date]

Explanation of the .Form bit:
http://allenbrowne.com/casu-04.html

If that still fails, you may find that the Name of the subform control is
not [Assisting Instructor Subform]. Its Name can be different to its
SourceObject (the name of the form you load into the subform control.)

BTW, the name Date can cause you grief as well. It is a reserved word in VBA
(for the system date), and in queries, so Access is likely to misunderstand
it. For an extensive list of the names to avoid, see:
http://allenbrowne.com/AppIssueBadWord.html
 
M

macejsc via AccessMonster.com

That's exactly what I needed!! Thank you! It works great now. Plus I was
able to start experimenting with the Visible property and really made the
form work a little better.

I'm having one little problem now though. I make the form visible, get all
the controls filled like I wanted, but I had to add two fields to get it to
specify the correct course and date so if we had courses the same day but for
different people I would confuse the data. Only thing is I want the First
and Last name fields to be invisible after data has been copied to it. I can
get the first name to disapper after I set the focus to the Last Name, but
once I set the focus back on the main form it won't let me change the visible
property of the Last Name. It keeps coming up with an error stating I can't
change the visible property of a control that has focus. The weird thing is
I just changed the focus to the Comments Here's what I have so far.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Forms![Student Info New Records]![Assisting Instructor Subform].Form![First
Name].Visible = True
Forms![Student Info New Records]![Assisting Instructor Subform].Form![First
Name].SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].Form![First
Name] = FN
Forms![Student Info New Records]![Assisting Instructor Subform].Form![Last
Name].Visible = True
Forms![Student Info New Records]![Assisting Instructor Subform].Form![Last
Name].SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].Form![Last
Name] = LN
Forms![Student Info New Records]![Comments].SetFocus
Forms![Student Info New Records]![Assisting Instructor Subform].Form![Last
Name].Visible = False
Forms![Student Info New Records]![Assisting Instructor Subform].Form![First
Name].Visible = False
Forms![Student Info New Records]![Comments].SetFocus
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
When I run the code, the error appears on the [Last Name].Visible = False
If I switch First Name and Last Name then it works, but whatever control is
referenced last is the one that cannot be set to invisible because it still
has focus. Could I set the focus to another field in the subform and then
set the Last Name Control to invisible?
 
A

Allen Browne

You don't need to SetFocus to the control in order to assign the value.

You do need to SetFocus to something else *before* you make it invisible.

Best to start a new thread for a new question.
 

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