Duplicate Field from Previous Record - 2003

oneilldm

Registered User.
Local time
Today, 13:08
Joined
Dec 10, 2008
Messages
19
I can use Ctrl-' (apostrophe) to copy the value of the same field in the previous record.

I would like to create a Command Button that would do the same thing.

Is there a way to do that?
 
Code:
[COLOR=teal]'Set focus to the field's control.[/COLOR]
Me.YourControl.SetFocus
SendKeys "^(')"
 
Perfect... Thank you!!!
 
OR if you'd like to automate it completely, without the user having to do anything, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record. The syntax varies slightly, depending on the datatype of the data:

For Date fields
Code:
Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
  YourDateControlName.DefaultValue ="#" &  Me.YourDateControlName & "#"
End If
End Sub

For Text fields
Code:
Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
  YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
End If
End Sub

For Numeric fields
Code:
Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
  YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom