Can't Copy Code from one database to another

D

dlhappy

Let me first state that I do not know VBA at all or really how to correctly
use the VBA window.

I have code that was given to me a long time ago when I had used Access 97 in
different databases. Those databases have been converted/saved to the new
format used Access 2007.

I recently created a new database (using Access 2007), Today, I decided that
I wanted two date fields that I used in my other databases.

In my old databases I have two fields, AddDate and EditDate. These fields
work as follows: AddDate - anytime a new record is entered in the database,
the AddDate field and the EditDate fields are automatically filled in to show
the current date. When an existing record is modified in any way, the AddDate
field remains unchanged, but the EditDate field is automatically updated to
show the current date (that is, today's date, the date of the update).

I thought that I could merely copy and paste the code from one of my other
databases to the recently created database in which I had already added the
AddDate and EditDate fields and used all of the same field
definitions/properties that I had in the old database.

The other database (hereinafter "old db") had the following tree (shown in
the VBA window):
Project - ABC
(Folder) Microsoft Office Access Class Objects
FormName

I tried in the new database, in the Database Visual Basic window, via the
various menu items to create/insert a folder called Microsoft Office Access
Class Objects (like in old db). All I could find is inserting a module or
class module. I tried both of those and tried pasting the code. Nothing
worked. Under the project name, I now have a folder named class modules and
two files? for that folder. I tried to remove/delete each one since nothing
works, and now all I get is a "file not found" error message when I try
removing any of them or the folder.

1. How can I delete these modules?

2. How can I insert MS Office Access CLASS OBJECTS (not modules)
and will this work with the code as does old db.

Ths is the actual code:

General - Declarations:

Option Compare Database

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub

------------------------------------------------------
Changing General to Form AddDate and Declarations changes to BeforeUpdate
the screen shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub

-------------------------------------------------------------------
Either AddDate or EditDate and AfterUpdate
shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_AfterUpdate()

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub
--------------------------------------------------------------------
Form Load
shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_AfterUpdate()

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub
 
G

Gina Whipp

dlhappy,

Well, there were a few excess lines in there, I removed those...

To get this code behind your form...

1. Go to Design View of the form that has the field *EDITDATE*

2. On the Ribbon, find and press the Code button (colored square looking
thingy)

3. Copy/Paste everything between Start Code and End Code in the Window that
opened in Step 2

'***Start Code

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date
End If

End Sub

'***End Code

4. Then go to Debug... Complie

5. ALL DONE! Report back with any problems.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

dlhappy said:
Let me first state that I do not know VBA at all or really how to
correctly
use the VBA window.

I have code that was given to me a long time ago when I had used Access 97
in
different databases. Those databases have been converted/saved to the new
format used Access 2007.

I recently created a new database (using Access 2007), Today, I decided
that
I wanted two date fields that I used in my other databases.

In my old databases I have two fields, AddDate and EditDate. These fields
work as follows: AddDate - anytime a new record is entered in the
database,
the AddDate field and the EditDate fields are automatically filled in to
show
the current date. When an existing record is modified in any way, the
AddDate
field remains unchanged, but the EditDate field is automatically updated
to
show the current date (that is, today's date, the date of the update).

I thought that I could merely copy and paste the code from one of my other
databases to the recently created database in which I had already added
the
AddDate and EditDate fields and used all of the same field
definitions/properties that I had in the old database.

The other database (hereinafter "old db") had the following tree (shown in
the VBA window):
Project - ABC
(Folder) Microsoft Office Access Class Objects
FormName

I tried in the new database, in the Database Visual Basic window, via the
various menu items to create/insert a folder called Microsoft Office
Access
Class Objects (like in old db). All I could find is inserting a module or
class module. I tried both of those and tried pasting the code. Nothing
worked. Under the project name, I now have a folder named class modules
and
two files? for that folder. I tried to remove/delete each one since
nothing
works, and now all I get is a "file not found" error message when I try
removing any of them or the folder.

1. How can I delete these modules?

2. How can I insert MS Office Access CLASS OBJECTS (not modules)
and will this work with the code as does old db.

Ths is the actual code:

General - Declarations:

Option Compare Database

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub

------------------------------------------------------
Changing General to Form AddDate and Declarations changes to BeforeUpdate
the screen shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub

-------------------------------------------------------------------
Either AddDate or EditDate and AfterUpdate
shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_AfterUpdate()

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub
--------------------------------------------------------------------
Form Load
shows:

Option Compare Database

Private Sub ADDDATE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub EDITDATE_AfterUpdate()

End Sub

Private Sub EDITDATE_BeforeUpdate(Cancel As Integer)

End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date

End If

End Sub

Private Sub Form_Load()

End Sub
 
D

dlhappy

Hi Gina:

Thank you very, very much.

Actually, I did have a problem in that I was unable to delete the old modules
and I could not save the new code that you supplied because I kept getting a
file not found error message. However, I was able to overcome the problem by
opening a backed-up earlier copy of the database that did not have the faulty
module/class module (it also did not have a number of additional records; so,
I exported the table to the older copy and then followed your directions,
pasted your code and everything was fine when I saved it. I then tested it by
editing a record and the EditDate field automatically updated.

Again, thank you very much and I really appreciate your help.

Allan

Gina said:
dlhappy,

Well, there were a few excess lines in there, I removed those...

To get this code behind your form...

1. Go to Design View of the form that has the field *EDITDATE*

2. On the Ribbon, find and press the Code button (colored square looking
thingy)

3. Copy/Paste everything between Start Code and End Code in the Window that
opened in Step 2

'***Start Code

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date
End If

End Sub

'***End Code

4. Then go to Debug... Complie

5. ALL DONE! Report back with any problems.
Let me first state that I do not know VBA at all or really how to
correctly
[quoted text clipped - 163 lines]
 
G

Gina Whipp

Allan,

Now you really are happy, just like your name!

You're welcome...
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

dlhappy said:
Hi Gina:

Thank you very, very much.

Actually, I did have a problem in that I was unable to delete the old
modules
and I could not save the new code that you supplied because I kept getting
a
file not found error message. However, I was able to overcome the problem
by
opening a backed-up earlier copy of the database that did not have the
faulty
module/class module (it also did not have a number of additional records;
so,
I exported the table to the older copy and then followed your directions,
pasted your code and everything was fine when I saved it. I then tested it
by
editing a record and the EditDate field automatically updated.

Again, thank you very much and I really appreciate your help.

Allan

Gina said:
dlhappy,

Well, there were a few excess lines in there, I removed those...

To get this code behind your form...

1. Go to Design View of the form that has the field *EDITDATE*

2. On the Ribbon, find and press the Code button (colored square looking
thingy)

3. Copy/Paste everything between Start Code and End Code in the Window
that
opened in Step 2

'***Start Code

Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Dirty Then
Me![EDITDATE] = Date
End If

End Sub

'***End Code

4. Then go to Debug... Complie

5. ALL DONE! Report back with any problems.
Let me first state that I do not know VBA at all or really how to
correctly
[quoted text clipped - 163 lines]
 

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