getting run time error 2465, help me!!!

  • Thread starter Edward Letendre
  • Start date
E

Edward Letendre

I have the following code that was created before I started on this project:

Option Compare Database 'Use database order for string comparisons

Function CalcKm()

Dim db As Database
Dim FormName As String, SubFormName
Dim eol As Single, bol As Single
Dim statint As Single, kmcount As Single
Dim getval As Variant
Dim fm As String
Dim yearstr As String
Dim Yearval As Integer


Set db = DBEngine.Workspaces(0).Databases(0)


FormName = Screen.ActiveForm.Name


getval = Forms(FormName)![Year]
If IsEmpty(getval) Or IsNull(getval) Then
MsgBox "No Year!", 48, ""
Exit Function
Else
yearstr = getval
End If

Yearval = Val(yearstr)

Select Case Yearval
Case 95: SubFormName = "ATS LINES 1995"
Case 96: SubFormName = "ATS LINES 1996"
Case 97: SubFormName = "ATS LINES 1997"
Case 98: SubFormName = "ATS LINES 1998"
Case 99: SubFormName = "ATS LINES 1999"
Case 2000: SubFormName = "ATS LINES 2000"
Case 2001: SubFormName = "ATS LINES 2001"
Case 2002: SubFormName = "ATS LINES 2002"
Case 2003: SubFormName = "ATS LINES 2003"
Case 2004: SubFormName = "ATS LINES 2004"
Case 2005: SubFormName = "ATS LINES 2005"
Case 2006: SubFormName = "ATS LINES 2006"
End Select

'MsgBox FormName, 48, ""


getval = Forms(FormName).Form![DoCalc]
If IsEmpty(getval) Or IsNull(getval) Or getval = "N" Then
' MsgBox "No End of Line!", 48, ""
Exit Function
End If

getval = Forms(FormName)(SubFormName).Form![End of Line]
If IsEmpty(getval) Or IsNull(getval) Then
' MsgBox "No End of Line!", 48, ""
Exit Function
Else
eol = getval
' MsgBox Str$(eol), 48, ""
End If

on the line getval = Forms(FormName)(SubFormName).Form![End of Line] I get
the following error message:

Run Time Error 2465 Access cannot find the field 'ATS LINES 2006' referred
to in your expressions.

I have created all of the forms, tables and queries associated with the year
2006, but the weird thing is that this program ran before with 2005 tables,
forms, queries, etc. I have simply copied and renamed and added all the 2006
info I could think of. If someone could explain to me why this program ran
before I made the changes and or something I might have missed, I would
appreciate it.

Edward Letendre.
 
E

Edward Letendre

I hate to reply to myself, but I have some extra information. Please help me
if you can.

in the line that is being highlighed when I debug the code:

getval = Forms(FormName) (SubFormName).Form![End of Line]

the values for each above are as follows:

getval is equal to Y

FormName is equal to ATS JOBS 2006 - which is the main or parent form

SubFormNae is equal to ATS LINES 2006 - which exists and is linked to a
query called SORTED LINES 2006, which is linked to the ATS LINES 2006 table

I can see the End of Line column in the ATS LINES 2006 table and the SORTED
LINES 2006 query.

As of now the ATS LINES 2006 table has no data in it, along with the ATS
JOBS 2006 table, as the year has just started.

Can someone explain the error RUN TIME ERROR 2465, access cannot find the
field 'ATS LINES 2006' referred to in your expressions.

Edward Letendre said:
I have the following code that was created before I started on this project:

Option Compare Database 'Use database order for string comparisons

Function CalcKm()

Dim db As Database
Dim FormName As String, SubFormName
Dim eol As Single, bol As Single
Dim statint As Single, kmcount As Single
Dim getval As Variant
Dim fm As String
Dim yearstr As String
Dim Yearval As Integer


Set db = DBEngine.Workspaces(0).Databases(0)


FormName = Screen.ActiveForm.Name


getval = Forms(FormName)![Year]
If IsEmpty(getval) Or IsNull(getval) Then
MsgBox "No Year!", 48, ""
Exit Function
Else
yearstr = getval
End If

Yearval = Val(yearstr)

Select Case Yearval
Case 95: SubFormName = "ATS LINES 1995"
Case 96: SubFormName = "ATS LINES 1996"
Case 97: SubFormName = "ATS LINES 1997"
Case 98: SubFormName = "ATS LINES 1998"
Case 99: SubFormName = "ATS LINES 1999"
Case 2000: SubFormName = "ATS LINES 2000"
Case 2001: SubFormName = "ATS LINES 2001"
Case 2002: SubFormName = "ATS LINES 2002"
Case 2003: SubFormName = "ATS LINES 2003"
Case 2004: SubFormName = "ATS LINES 2004"
Case 2005: SubFormName = "ATS LINES 2005"
Case 2006: SubFormName = "ATS LINES 2006"
End Select

'MsgBox FormName, 48, ""


getval = Forms(FormName).Form![DoCalc]
If IsEmpty(getval) Or IsNull(getval) Or getval = "N" Then
' MsgBox "No End of Line!", 48, ""
Exit Function
End If

getval = Forms(FormName)(SubFormName).Form![End of Line]
If IsEmpty(getval) Or IsNull(getval) Then
' MsgBox "No End of Line!", 48, ""
Exit Function
Else
eol = getval
' MsgBox Str$(eol), 48, ""
End If

on the line getval = Forms(FormName)(SubFormName).Form![End of Line] I get
the following error message:

Run Time Error 2465 Access cannot find the field 'ATS LINES 2006' referred
to in your expressions.

I have created all of the forms, tables and queries associated with the year
2006, but the weird thing is that this program ran before with 2005 tables,
forms, queries, etc. I have simply copied and renamed and added all the 2006
info I could think of. If someone could explain to me why this program ran
before I made the changes and or something I might have missed, I would
appreciate it.

Edward Letendre.
 
R

Robert Morley

It would appear that it can't find the subform...is it perhaps because the
table and subform use the same name?

It's good practice to disambiguate the reference, and you may also want to
try putting it on separate lines, in order to help debug the problem, so for
example...

Dim fMain As Form
Dim fSub As Form
Dim cMain As Control
Dim cSub As Control

Set fMain = Forms(FormName)
Set cMain = fMain.Controls(SubFormName)
Set fSub = cMain.Form
Set cSub = fSub.Controls("End of Line") ' or fSub![End of Line]

You probably wouldn't normally be quite so verbose, but at least if the
above code doesn't work, you'll know EXACTLY where the problem lies, and
hopefully be able to fix it from there.

Oh, and just a minor suggestion for the code...rather than writing a Select
Case statement for the year, try the following:

If Yearval < 100 Then Yearval = Yearval + 1900
SubFormName = "ATS LINES " & Format(Yearval)



Rob

Edward Letendre said:
I hate to reply to myself, but I have some extra information. Please help
me
if you can.

in the line that is being highlighed when I debug the code:

getval = Forms(FormName) (SubFormName).Form![End of Line]

the values for each above are as follows:

getval is equal to Y

FormName is equal to ATS JOBS 2006 - which is the main or parent form

SubFormNae is equal to ATS LINES 2006 - which exists and is linked to a
query called SORTED LINES 2006, which is linked to the ATS LINES 2006
table

I can see the End of Line column in the ATS LINES 2006 table and the
SORTED
LINES 2006 query.

As of now the ATS LINES 2006 table has no data in it, along with the ATS
JOBS 2006 table, as the year has just started.

Can someone explain the error RUN TIME ERROR 2465, access cannot find the
field 'ATS LINES 2006' referred to in your expressions.

Edward Letendre said:
I have the following code that was created before I started on this
project:

Option Compare Database 'Use database order for string comparisons

Function CalcKm()

Dim db As Database
Dim FormName As String, SubFormName
Dim eol As Single, bol As Single
Dim statint As Single, kmcount As Single
Dim getval As Variant
Dim fm As String
Dim yearstr As String
Dim Yearval As Integer


Set db = DBEngine.Workspaces(0).Databases(0)


FormName = Screen.ActiveForm.Name


getval = Forms(FormName)![Year]
If IsEmpty(getval) Or IsNull(getval) Then
MsgBox "No Year!", 48, ""
Exit Function
Else
yearstr = getval
End If

Yearval = Val(yearstr)

Select Case Yearval
Case 95: SubFormName = "ATS LINES 1995"
Case 96: SubFormName = "ATS LINES 1996"
Case 97: SubFormName = "ATS LINES 1997"
Case 98: SubFormName = "ATS LINES 1998"
Case 99: SubFormName = "ATS LINES 1999"
Case 2000: SubFormName = "ATS LINES 2000"
Case 2001: SubFormName = "ATS LINES 2001"
Case 2002: SubFormName = "ATS LINES 2002"
Case 2003: SubFormName = "ATS LINES 2003"
Case 2004: SubFormName = "ATS LINES 2004"
Case 2005: SubFormName = "ATS LINES 2005"
Case 2006: SubFormName = "ATS LINES 2006"
End Select

'MsgBox FormName, 48, ""


getval = Forms(FormName).Form![DoCalc]
If IsEmpty(getval) Or IsNull(getval) Or getval = "N" Then
' MsgBox "No End of Line!", 48, ""
Exit Function
End If

getval = Forms(FormName)(SubFormName).Form![End of Line]
If IsEmpty(getval) Or IsNull(getval) Then
' MsgBox "No End of Line!", 48, ""
Exit Function
Else
eol = getval
' MsgBox Str$(eol), 48, ""
End If

on the line getval = Forms(FormName)(SubFormName).Form![End of Line] I
get
the following error message:

Run Time Error 2465 Access cannot find the field 'ATS LINES 2006'
referred
to in your expressions.

I have created all of the forms, tables and queries associated with the
year
2006, but the weird thing is that this program ran before with 2005
tables,
forms, queries, etc. I have simply copied and renamed and added all the
2006
info I could think of. If someone could explain to me why this program
ran
before I made the changes and or something I might have missed, I would
appreciate it.

Edward Letendre.
 

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