Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dim varDummy As Variant 1

Status
Not open for further replies.

steve1961

Technical User
Jun 10, 2003
12
IE
I have a function called "HasProperty" which is part of another function called "Public Function CarryOver" taken from ( few years back. This code was working for years but for some strange reason is now showing the following error in Line 6 below:

varDummy = obj.Properties(strPropName)


Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function

Could anyone possibly explain why this is happening with this code. Any assistance would be greatly appreciated.
 
You show the line where it breaks, but you forgot to post the error.
 
Sorry about that:

Run-Time error '1245'

You entered an expression that has an invalid reference to the property ControlSource

Funny thing is this code has been running for last 5 years with no problem and then this error starts showing up.
 
If this object is a control bound to a field of a table, maybe something has been changed on the table structure.

 
Either you have commented out this line
On Error Resume Next
(which it does not look like you did)
Or there is some kind of corruption. My guess it got corrupted. It looks as if it is ignoring the error handler somehow.

If you did not have the " On Error Resume Next" you would get this error:
"You entered an expression that has an invalid reference to the property ControlSource"

When you are passing in an object that does not have a control source.

But the error handler takes care of it. But for some reason it is not. It looks like the error handler is being ignored. I would do the following:
1) Ensure "Option Explicit" set for all modules
2) Debug and compile the project from the vba window
3) Correct any compile errors
4) Compact and repair the database
5) Test
If no joy
6) Build a blank database
7) import al tables, forms, queries, reports, modules, macros into the new db. Ensure you first import the tables, then do the rest
8) Test

Also does this fail if you do pass an object that has a controlsource property?
 
I have created a new databases using the current code (TEST 1.MDB) and a previous version of this code (TEST 2.MDB)and posted the links to the DB below it.

Run-Time error '1245'
You entered an expression that has an invalid reference to the property ControlSource

1.mdb



Run-Time error '3265'
Item not found in this collection
2.mdb



Perhaps someone could have a look and tell me where the underlying problem is occurring.

Thanks for the assistance
 
MajP,

I appreciate your reply and have tried the following suggestions

1) Ensure "Option Explicit" set for all modules
2) Debug and compile the project from the vba window
3) Correct any compile errors
4) Compact and repair the database
5) Test
If no joy
6) Build a blank database
7) import al tables, forms, queries, reports, modules, macros into the new db. Ensure you first import the tables, then do the rest
8) Test


but still no joy. I'll keep plugging away and find out where this happening.

Thanks again
 
Steve,
I do not get an error. If I add a cosignee it copies the information. So I think it is your VB settings.

So I googled "vba error handler stops working"
I got a possible:
"Go into TOOLS > STARTUP and make sure the USE ACCESS SPECIAL KEYS checkbox is checked."
and/or
"In VBE check Tools > Options > Genreal > Error Trapping."
Make sure not set to "all errors"

The next thing is the function CarryOver. Either I am missing something or that is some of the goofiest code I have ever seen. Is the purpose really to copy values from the last record to a new record? That could be done with about 3 lines of code.
 
Also your two examples are vastly different. One does not even execute any code. Are you sure these are correct?
 
MajP,

Your genius in solving this error will go unnoticed. The error was solved as you indicated:

"In VBE check Tools > Options > Genreal > Error Trapping."
Make sure not set to "all errors"

I just can't figure out why this is happening all of sudden when the code ran fine for the past few years.


"Is the purpose really to copy values from the last record to a new record? That could be done with about 3 lines of code."
Yes, I tried doing this with 3-4 lines of code in the past but I think was getting the problem after I copied the last record I was not able to copy a new record to the next line. Any suggestions would be appreciated.


Anyways, thank you very much for your assistance.

 
There are lots of ways to do this, but it depends on how exactly do you want it to work. What exactly are you trying to accomplish? Your events seem strange. Right now it looks as once you enter a jobdetail, it creates a new record with that detail information. Do you really want to create a copy record everytime you create a record?

One way this is done by setting the default values of the controls. So if you go to a new record, the default values are set to the previous record values. If it is a new record and no details currently exist you could set the defaults to nothing or some other set of values.

1)If they select a Job and there are no job details. When they enter a job detail what do you want if anything?
2)If there are jobdetails, for a given job what would you like to happen?
3) When do you want it to happen, when they create a record or enter a new record.

 
"Do you really want to create a copy record everytime you create a record?" Currently for 90% of new records on each job details line it's always the same except for 1 field.

But yes I did play with the default values of the control in the past. I'll take your suggestion and try to do this again and see what happens.

Thanks again for your valuable input.
 
This works for me, if you get rid of the other code.
Private Sub Form_Current()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
If Me.NewRecord Then
If rs.RecordCount > 0 Then
rs.MoveLast
With Me
.Weight.DefaultValue = rs!Weight
.ConsigneeID.DefaultValue = rs!ConsigneeID
.CollectionDate.DefaultValue = rs!CollectionDate
'all other fields
End With
Else
'sets the default to nothing
With Me
.Weight.DefaultValue = ""
.ConsigneeID.DefaultValue = ""
.CollectionDate.DefaultValue = ""
'all other fields
End With
End If
End If
End Sub
 
Yes, this works for me as well.
You are much quicker then a newbie like me.


MajP,
Many many thanks again for your valuable input////
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top