?
Solved

Creating a History Field in Microsoft Access 2007

Posted on 2011-02-11
17
Medium Priority
?
1,329 Views
Last Modified: 2012-05-11
Hi

I am trying to create a history field to record all actions typed in the notes field of my form.

When you type any data in the notes field and click the save button, the data in the notes section is copied to history field, and any data in the notes field is removed. To do this i am using the following code:

----------------------------------
To update the History field with the data from the Notes field.
Private Sub txtSatNavNotes_AfterUpdate()

     If Me.txtSatNavHistory = "" Then
        Me.txtSatNavHistory = Me.txtSatNavHistory & Me.txtSatNavNotes
    Else
        Me.txtSatNavHistory = Me.txtSatNavHistory & vbNewLine & Me.txtSatNavNotes
    End If

End Sub

When i click my Save button, it clears the Notes field:

Me.txtSatNavNotes = ""
---------------------------------------

The issue i have is that the history field in the underlying table is not being populated with the data that is being copied to the history field that is on the form, even though it is showing when you load the form.

What am i doing wrong?

I hope this makes sense.
kind regards
DGI
0
Comment
Question by:dgi001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34872629
What does the Save button do?  There might be a timing issue here.  Make sure you don't clear the Notes textbox before saving.  Save first.
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 34872642
Also, use Nz() to check for nulls.  "" is not the same as a Null field:

If Nz(Me![txtSatZNavHistory].Value) <> "" Then

This will cover both Nulls and empty strings in the field.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 34872652
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 21
ID: 34872770
My try this:

Private Sub txtSatNavNotes_AfterUpdate()

     If Me.txtSatNavHistory = "" Then
        Me.txtSatNavHistory = Me.txtSatNavNotes
    Else
        Me.txtSatNavHistory = Me.txtSatNavHistory & vbNewLine & Me.txtSatNavNotes
    End If

End Sub

Open in new window



I have fioudn inthe 15+ years working with Acess that  your method can lead to dfata loss.

I find it much better to  save each new notes as a separate record. This has many advantages. For example I use a separate date/time field. This allows the notes to be sorted and filtered.

0
 

Expert Comment

by:Iamme
ID: 34872785
A question, is "Me.txtSatNavHistory" a textbox?...
you should use "Me.txtSatNavHistory.TEXT" instead
of "Me.txtSatNavHistory"
0
 

Author Comment

by:dgi001
ID: 34915780
Hi Capricorn

I have looked at the Column History but i cant get it to work.

My table tblSimDetails has a column called SIMNotes, memo data type and append only set to yes.

I have a form called frmSimDetails where i am trying to copy the data from the txtSimNotes field to the txtSIMHistory field by making the txtSIMHistory control source set to:

=ColumnHistory([RecordSource],"txtSIMNotes","[txtSIMNoID]=" & Nz([txtSIMNoID],0)).

When i load the form, the txtSIMHistory reads #error.

Am i being stupid in that the [RecordSource] shoudl be the name of the table or form? I did but those details in but that didnt work either.

What am i doing wrong?

Kind regards
DGI
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34915824
what is the Record Source of the form?
0
 

Author Comment

by:dgi001
ID: 34925566
tblSimDetails
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34925685
tblSimDetails  
fields  
SIMNoID     > is this Number Data Type or Text?
SIMNotes   > Memo


try this


=ColumnHistory([RecordSource],"SIMNotes","[SIMNoID]=" & Nz([txtSIMNoID],0))
0
 

Author Comment

by:dgi001
ID: 34925873
SimNoID is an autoNumber data type

I tried what you suggested and still comes up with #error.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34925904
how about this

=ColumnHistory("tblSimDetails","SIMNotes","[SIMNoID]=" & Nz([txtSIMNoID],0))
0
 

Author Comment

by:dgi001
ID: 34926026
Hi

I dont know what is stopping this from working on all my forms as i have created a test database from scratch and it works using =ColumnHistory([RecordSource],"SIMNotes","[SIMNoID]=" & Nz([txtSIMNoID],0)).

I wonder if some code or other settning is preventing this from working? i am not quite sure what to do next, except rebuild my forms?

regards
DGI
0
 

Author Comment

by:dgi001
ID: 34926167
I have imported all my tables, forms and modules into a new database and this now works?????

Does this mean that my database is corrupt or because its Micrsoft?

kind regards
DGI
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34926175
your form could be corrupted :-(  

try this,

delete the  =ColumnHistory([RecordSource],"SIMNotes","[SIMNoID]=" & Nz([txtSIMNoID],0))

from the  Control Source of the textbox

save the form

do this

Tools >Database utilities > compact and repair database


* do a decompile
   see this link
http://www.granite.ab.ca/access/decompile.htm

* after that,
* open the VBA window and do
     Debug > Compile
     correct any errors raised

* do a compact and repair


Now go back to the form and add to the Control Source  of the textbox

=ColumnHistory([RecordSource],"SIMNotes","[SIMNoID]=" & Nz([txtSIMNoID],0))


0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34926182
oops, cross posting... :-)
0
 

Author Comment

by:dgi001
ID: 34926259
I will do this over the weekend and get back to you.
0
 

Author Closing Comment

by:dgi001
ID: 34950045
If i ignore the fact that my database was corrupt, and i have now resolved this, this suggestion resolved the my request.

Thanks to all who replied.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question