Buton to fill in field from previous record

thedys

New member
Local time
Yesterday, 19:49
Joined
Jan 11, 2017
Messages
7
Hi I was wondering if someone can answer if this is possible and if it is how I should do it.

I've a form with a selection of personal information it's quite likely that information from one customer to the next would be shared. Therefore I'd like to add a button that once you press it would look up AddressLine1 from the previous record eg ID-1 and then enter it into the AddressLine1 field for the current customer.

Is this possible? I've found a number of tutorials that have it when creating a new record but not once that records been created, any help would be much appreciated.
 
If you set the default value of the control(s) to the value of the current record in the after update event of the control then any new record will have that value.

Sample Code;
Code:
Private Sub [I]txtYourControl[/I]_AfterUpdate()

    If Not IsNull(Me.[I]txtYourControl[/I]) Then
        Me.[I]txtYourControl[/I].DefaultValue = Me.[I]txtYourControl[/I]
    End If

End Sub

Where txtYourControl is the name of the control on your form.
 
Code:
With RecordsetClone
    If NewRecord Then
        .MoveLast
    Else
        .Bookmark = Recordset.Bookmark
        .MovePrevious
        If .BOF Then Exit Sub
    End If
    AddressLine1 = .Fields("AddressLine1").Value
End With
 
That syntax is not quite right...

Me.txtYourControl.DefaultValue = Me.txtYourControl

needs to be

Me.txtYourControl.DefaultValue = """" & Me.txtYourControl & """"

The nice things is, it'll work regardless of the Datatype involved!

And this code does assume that you're entering Record after Record, in a single session of Access.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom