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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database II Project

Status
Not open for further replies.

Ninabunny

Programmer
Jul 24, 2000
70
US
Currently I am creating a database with PKs and concantenated FKs. My problem is this:<br>I need to save the previous address on the tblNames if it is changed.&nbsp;&nbsp;This would be saved to an address table built specifically for saving old addresses.&nbsp;&nbsp;This address table has a PK which is an autonumber then the Fk which is the PId(personal id) then address field, City, State,Zip,Timestamp, and User.<br>I need to use an append query, which I have created but am in need of the code(visual basic).&nbsp;&nbsp;I realize it should be on BeforeUpdate, thanks elizabeth, and use the oldvalue but how?&nbsp;&nbsp;I hope I don't sound too garbled?
 
Good morning, <br><br>Instead of a append query, you could try something like this code.&nbsp;&nbsp;This is OTTOMH, so you might have to mess with it a bit.&nbsp;&nbsp;(Plus it's only 7:10 am, so the caffeine hasn't kicked in yet)<br><br>****Begin Code*********<br><br>Sub SaveOldAddress()<br>dim rst as recordset<br><br>set rst= currentdb.openrecordset(&quot;tblOldAddresses&quot;)<br><br>rst.addnew<br>&nbsp;&nbsp;rst!PID = Me!NameOfIDFieldOnForm.oldvalue<br>&nbsp;&nbsp;rst!address = Me!NameOfAddressFieldOnForm.oldvalue<br>&nbsp;&nbsp;...etc...<br>rst.update<br><br>rst.close<br>set rst=nothing<br><br>End Sub<br>****End Code*********<br><br>You could then call this procedure in the BeforeUpdate event of each of the address fields.<br><br>I hope this helps.&nbsp;&nbsp;Let me know if you need more explanation.<br><br> <p>Kathryn<br><a href=mailto: > </a><br><a href= > </a><br>
 
Well that would work to append a table but I am just appending the old address iwth the fields associated with it.<br>
 
I think Kathryn did a good work, and all you have to do is to modify it a little bit to fit your needs.<br><br>Sub SaveOldAddress()<br>dim rst as recordset<br><br>set rst= currentdb.openrecordset(&quot;tblOldAddresses&quot;)<br><br>rst.addnew<br>&nbsp;&nbsp;rst!FK = Me!NameOfIDFieldOnForm<br>&nbsp;&nbsp;rst!address = Me!NameOfAddressFieldOnForm.oldvalue<br>&nbsp;&nbsp;rst!City = ME!NameOfCityFieldOnForm.oldvalue<br>&nbsp;&nbsp;...etc...<br>rst.update<br><br>rst.close<br>set rst=nothing<br><br>End Sub<br><br>of course, you have to know which fields will be edited if the user changes the address (.oldvalue), and which wont be changed like (personal ID)<br><br>Hope this would help YOU... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
I thought old value kept its value and never reset?<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top