PDA

View Full Version : Error 2465



nepotist
09-03-2008, 08:35 AM
If CurrentProject.AllForms("ProjectEdit").IsLoaded = True Then
LinkID = Forms!projectedit.!Processedtrips.!LinkNumber.Value
projVol = Forms!projectedit!Processedtrips!LinkTrips.Value
TripType = Forms!projectedit!Processedtrips!Type.Value
ExcCap = Forms!projectedit!Processedtrips!AvailCap.Value
Else
LinkID = Forms!NewProject!Processedtrips!LinkNumber.Value
projVol = Forms!NewProject!Processedtrips!LinkTrips.Value
TripType = Forms!NewProject!Processedtrips!Type.Value
ExcCap = Forms!NewProject!Processedtrips!AvailCap.Value


the above is a code that i have in my module.

there are basically to forms newproject and project edit forms that use processedtrips as a subform and based on the form active/loaded i would do the calculations
not i get an error 2465 with the above code

I am debugging using the stepin to function or f8 key and i make sure that one of the main forms that is newproject or projectedit form is open
It first gave me a error saying that there is no such form existing when the code was some thing like this
linkid = forms!form_newproject!form_processedtrips!linkid.value

so i removed the from word in front of the newproject and processedtrips and now is gives me an error saying that the field processedtrips not found so i add back the form word back to the processedtrips but still of no use

I even tried to code some thing like this
linkid = forms!newproject.form!processedtrips.form!linkid.value

still it isnt of any use

Please some one help with any clues and ideas

CreganTur
09-03-2008, 08:48 AM
From what I can see of your code, it looks like the form 'projectedit' is the current, active form. Have you tried using 'Me'? It really cleans up referencing the current, active form.

If CurrentProject.AllForms("ProjectEdit").IsLoaded = True Then
LinkID = Me.LinkNumber.Value
projVol = Me.LinkTrips.Value
TripType = Me.Type.Value
ExcCap = Me.AvailCap.Value
Else
LinkID = Me.LinkNumber.Value
projVol = Me.LinkTrips.Value
TripType = Me.Type.Value
ExcCap = Me.AvailCap.Value

Also, when you post code please wrap it in VBA tags (click the green VBA button)- this will format your code according to VBIDE and make it easier to read.

nepotist
09-03-2008, 09:01 AM
You are right the vba project edit or the newproject will the current form depending on the scenario but these forms have a sub form called processed form. The reason i am not using a me!... here is because this code is written to assign values to the variables based on the values of the processed form and these values change with the new project and project edit form. and the function or the calculation will then be done. I have written this code in a module and will call it when needed

and would me!linkid.value do it casue the lnkid is a part of subform

OTWarrior
09-05-2008, 03:17 AM
this line:

LinkID = Forms!projectedit.!Processedtrips.!LinkNumber.Value

has both . and ! so should be:
LinkID = Forms!projectedit!Processedtrips!LinkNumber.Value


Anyway, does the following do the trick?

If CurrentProject.AllForms("ProjectEdit").IsLoaded = True Then
With Forms!projectedit!Processedtrips
LinkID = !LinkNumber.Value
projVol = !LinkTrips.Value
TripType = !Type.Value
ExcCap = !AvailCap.Value
End With
Else
With Forms!NewProject!Processedtrips
LinkID = !LinkNumber.Value
projVol = !LinkTrips.Value
TripType = !Type.Value
ExcCap = !AvailCap.Value
End With
End If

or, with CreganTur's use of Me statement (which is much neater :D):

If CurrentProject.AllForms("ProjectEdit").IsLoaded = True Then
With Me
LinkID = .LinkNumber.Value
projVol = .LinkTrips.Value
TripType = .Type.Value
ExcCap = .AvailCap.Value
End With
End If

nepotist
09-05-2008, 11:28 AM
Well I guess you looked at the first line of the code where you can see the . after the form name, but that was just the typo.the other line of cdes dont have it. in short my actuall code did not have that and it dint work , I tried your codes too and still it dosent work. the problem with all the codes that i have tried is that it says the subform that is the processedtrips is not available the actuall error says this " field processedtrips mentioned in the macro or the vb code cannot be found" it you look at the error it recognizes the form as a field but not as an object. I have been trying to figure it out but of no use. this is one thing that is preventing me to processed further.

Please anyone any more suggestions, to mention i even verified the form name and also tried it with different form name.

OTWarrior
09-08-2008, 01:34 AM
Normally people copy and paste the exact code when posting, in order to show exactly where there error could happen, so I am sorry for assuming you had done this. I figured it was a typo as VB would pick up on it normally, but I am sure everyone has made a typo type mistake that stops code from running (I have a a number of occasions).

Just wondering, but when does this code run? Is it on load of a form, timer event or when a button is pressed? The fact that it says it can't find the form would imply that the form is loaded yet, or isn't being referenced correctly.

Does creating an object variable help?

dim FormStart as Object
set FromStart = "ProjectEdit"