Full Version: Copying default value from previous record
UtterAccess Forums > Microsoft® Access > Access Forms
projecttoday
How do you pass the value of a textbox on a form to the next new record (as the default)? Or rather, how do you retrieve as a default the value in the previous record? I believe there is a way to do this but can't think of it. I am trying to save entering the same value over and over as new records are entered.
obert
ansentry
Put this code behind the On Crrent event of your form, Change the code in Blue to suit.
CODE

    Dim rs As Object
    Set rs = Me.Recordset.Clone
    
    If rs.EOF Or Not Me.NewRecord Then
        ' don't do anything if there's no records or it is not a new record
    Else
        With rs
            
            .MoveLast
                      
           [color="blue"] Me![txtVehicleMake] = .Fields("VehicleMake")[/color]
           'Name of the control on your form      Name of the field in your table
          '
        End With
    End If

<
projecttoday
That worked great, John. Thanks for your help! You're terrific.
I have another similar question you might be able to answer. In a subform grid if you have a column that is a date, how would you check to see that new entries in the subform date field are higher than the one above it?
Robert
bigfoot53
Hello,
Is it possible to retreive data form a field on the previous days record and put in a form and a table ?
thanks
Bruce
projecttoday
Yes, but it sounds like you need a query for that. Start and new thread and give the details of what you're trying to do.
dashiellx2000
If you want to check that the date on a new record is greater then the maxium date already in the recordset, you can use a DMax in the validation.
If you are trying to get the date from the previous record in the table ragardless of the actual maximum date in the recordset, you'd need to use code like:
CODE
Dim rs As Object    
Set rs = Me.Recordset.Clone        
     With rs                        
          .MoveLast                                  
               If Me!DateField <= .Fields("DateField") Then
                    MsgBox "incorrect date entered"
               End if
     End With

HTH.
projecttoday
That makes sense. Only in this case it's not the whole table, just the records on the existing subform. I could use a .movenext loop. Thanks.
bigfoot53
I dont want to move the date i need to move data from say yesterday to the current day.
dashiellx2000
Well if the subform is based on a query that only contains records for one parent and you are only interested in the date being the greater then the Max date already entered, a DMax will probably be easier.
TH.
dashiellx2000
This does sound like something different that what the OP asked. I would also recommend you start a new thread with what you are actually trying to achive detailed.
TH.
projecttoday
Thanks for your help. I'm working on it.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.