Default value to previous record not working

  • Thread starter Thread starter Hugh self taught
  • Start date Start date
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 & """"
 
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?
 
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?
 
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.
 
Back
Top