Update Query to autofill date

could very well be... Having multiple objects with the same name has some strange side effects....

There is a reason for these naming conventions! Stick to them!
 
I'm right clicking on the date of contact field in the form's design view, selecting the event tab and entering the code in the After Update bit.

Are you actually in the VBA editor (clicking on the little box with 3 dots at the end of the field? If you are entering it in just the field, then it will throw an error.
 
Are you actually in the VBA editor (clicking on the little box with 3 dots at the end of the field? If you are entering it in just the field, then it will throw an error.

I am now, and after renaming my fields and forms I've now progressed from a lack of 'Me.' error message to a new message. I do like progress though :)

the error message is:

Invalid Outside Procedure

This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.
 
LOL *OUCH*

You are using David's line?

Me.DeadlineDate = Nz(Me.DateOfContract+14,"")

I am now lol

Still doesn't work though - same error message. A bottle of bubbly to the first person to solve it!
 
Can anyone please help with this? I spent all day on it yesterday and still haven't solved it!
 
Can you attach your problem database? Using davids code and using the ... to write said code, I really dont see what can be wrong?

Is your dateofcontact still on the form and is it still on the form bound to the table where you maybe removed it?
 
Can you attach your problem database? Using davids code and using the ... to write said code, I really dont see what can be wrong?

Is your dateofcontact still on the form and is it still on the form bound to the table where you maybe removed it?

I'm afraid I can't - IT policy won't let me :(
 
Are people seriously telling me that this problem has never come up before?

That is, Access doesn't recognise the object 'Me.' when I use it in code? I can't believe there is anything but a simple answer to this and I'm tearing what little hair I have left out here!!!
 
Are people seriously telling me that this problem has never come up before?

That is, Access doesn't recognise the object 'Me.' when I use it in code? I can't believe there is anything but a simple answer to this and I'm tearing what little hair I have left out here!!!

Well, the problem is, the advice that was given was sound and should work. A lot of times, it's something small or a miscommunication and seeing the db usually clears up the issue. But since you cannot post the db, it's tough to troubleshoot with just going by description. Would it be possible for you to create a dummy db with the offending code being identical to your database?

Just occurred to me...is the form where the code is a subform? When referencing a control on a subform, it's different than referencing a control on a form.
 
Well, the problem is, the advice that was given was sound and should work. A lot of times, it's something small or a miscommunication and seeing the db usually clears up the issue. But since you cannot post the db, it's tough to troubleshoot with just going by description. Would it be possible for you to create a dummy db with the offending code being identical to your database?

Just occurred to me...is the form where the code is a subform? When referencing a control on a subform, it's different than referencing a control on a form.

I'm sure it's small, that's why I'm tearing my hair out lol.

I know the advice is sound and the responses have been quick so I'm not complaining, just frustrated it's still there.

I'm afraid IT policy won't let me upload any files outside of the system, it's that strict so I can't post the DB.

I'll try to explain as best I can

I have two tables - Customers & Incidents with a one-to-many relationship
The forms for entering data into these tables are created by queries.
The date fields I want to change are in the Incidents table, so:

I enter info into the customer table through the form;
I click a button to open a filtered Incidents form related to the Customer table;
I enter the date into the Date of Contact field and then I want the Deadline Date field to be automatically generated using the afterupdate event.

I use the code mentioned above and it tells me 'Microsoft Access doesn't recognise the object Me.'

That's about it. Not sure what to do now!
 
Then make the db at home or stick it on a USB, without the db I know I am quite stuck... Even a screenshot of the code would be helpfull.


I have no clue other than what I ahve posted already as to what you are doing wrong...

You are entering the code where the cursor starts, between the "Sub" and "End Sub" not outside it?
 
I don't know guys...the error message is invalid outside procedure

The code is as follows:

Private Sub DateofContact_AfterUpdate()
Me.Deadlinedate = Nz(Me.DateofContact + 14, "")
End Sub

The message I get is:

This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.

I did put this code in the Afterupdate event part of the properties of the date of contact field. That was when I was getting the message 'Micorsoft Access doesn't recognise the object me.'
 
I'll try and recreate your db based on the info you provided and see what I can do. Couple of questions:

1. Date of Contact is stored in what Table?
2. Deadline Date is stored in what Table?

Also, is there a reason why you are storing the Deadline Date? You could always calculate the Deadline Date on the fly since it's related to the Date of Contact.

EDIT:
I think I see the problem. You have 2 forms open, so i'm guessing that is where the issue is arising. Instead of using Me, use the full object name:

Forms!FormName!ControlName


I'll still try to recreate the issue, but give that a whirl
 
Last edited:
Ah, got your email and found the form...
This is the entire coding behind the form
Code:
Option Compare Database

[B][U]End Sub[/U][/B]
Private Sub ActionNotes_Enter()

End Sub

Private Sub DateofContact_AfterUpdate()

End Sub

Private Sub IncidentNotes_Enter()

End Sub
There is a erroneous "end sub" there, which is the problem.
Remove all the "extra" blank stuff and/or only the "faulty" end sub and this will work.
 
Great! - Um...which is the erroneous end sub then?

Or...how should it look!?
 
The bolded and underlined one....
Sub...
End sub

That is the only valid order / valid combination.... Anything else will error out...

You should remove any empty subs anyways, leaving only the first line (Option Compare Database)
Also you "should" require variable declaration (Tools > Options, tick the box in the "editor" tab)
 

Users who are viewing this thread

Back
Top Bottom