Default value to previous record not working

H

Hugh self taught

Hi All,

I'm using Access 2007 & my database is 2003 format.
I've tried the following in the Afterupdate of the relevant control but when
I go to a new record I have blank fields. Any suggestions as to why this is
not working? There are 3 fields I want to replicate on, none of which are
working.

Me!EvtCompID.DefaultValue = """" & Me!EvtCompID.Value & """"
 
L

Linq Adams via AccessMonster.com

Me!EvtCompID.DefaultValue = """" & Me!EvtCompID.Value & """"
"""" & Me.YourControlName.
Value & """"

Your code is valid, which means that the AfterUpdate event is not running.

One possibility is that you're populating the fields progamatically. A
control's AfterUpdate event will only fire if data is either typed into it,
or pasted into it. Populating it thru code won't fire it; you have to
specifically cqall the event.

Another possibility is that you haven't declared the folder holding the
database to be 'Trusted." Code does not run in 2007 unless your database
resides in a folder that has been declared a “trusted†location.

To trust your folder, click:

Office Button (top left)
Access Options (bottom of dialog)
Trust Center (left)
Trust Center Settings (button)
Trusted Locations (left)
Add new location (button)
 
H

Hugh self taught

Hi Linq,

The fields are all combo boxes. Location is trusted and all other
functionallity is working. What I did find that is working for me is the
following sample posted by Arvin Meyer

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim SQL As String
Dim db As DAO.Database

strSQL = "SELECT Max(ID) AS MaxID FROM MyTable;"

Set db = CurrentDb
Set rst1 = db.OpenRecordset (strSQL)

strSQL = "Select * From MyTable Where ID =" & rst1!MaxID

Set rst2 = db.OpenRecordset(strSQL)

' Now start setting your form's values
With rst2
Me.txtLastName = !LastName
Me.txtWhatever = !Whatever
' etc. to selective form controls
End With

I'd put this code in a command button. Add Error Handling and close your
objects, and you will get the last record to fill your form every time you
click the button.

Would it be that the query behind the cbo's is causing my original code not
to fire?
 
H

Hugh self taught

Hi Linq,

The fields are all combo boxes. Location is trusted and all other
functionallity is working. What I did find that is working for me is the
following sample posted by Arvin Meyer

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim SQL As String
Dim db As DAO.Database

strSQL = "SELECT Max(ID) AS MaxID FROM MyTable;"

Set db = CurrentDb
Set rst1 = db.OpenRecordset (strSQL)

strSQL = "Select * From MyTable Where ID =" & rst1!MaxID

Set rst2 = db.OpenRecordset(strSQL)

' Now start setting your form's values
With rst2
Me.txtLastName = !LastName
Me.txtWhatever = !Whatever
' etc. to selective form controls
End With

I'd put this code in a command button. Add Error Handling and close your
objects, and you will get the last record to fill your form every time you
click the button.

Would it be that the query behind the cbo's is causing my original code not
to fire?
 
B

BruceM

I can't make out if you are saying the code works or it doesn't. It seems
to me you would need something like:

Me.txtLastName = rst2!LastName
etc.
 

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