Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeating the last record 2

Status
Not open for further replies.

TerryEA

Technical User
Jun 20, 2004
99
GB
Hi all

Is there an easy way to do this:

I need to enter records into a form, several at a time. To save repetitive typing I want some of the fields to automatically be populated with values from the last record I entered, in that particular batch. Once the batch is finished, or say when Access is closed, the values would not be remembered and not auto-populated until a new record is added again.

I used to do this in an old database, which had such a facility, just by pressing F4 on each field.
 
In the AfterInsert event procedure of the form set the DefaultValue property of each relevant controls to their actual Value property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV

I tried your suggestion using the following code, in the After Update Property of the form but I get a type mismatch error. Have I got the code right for the field "Reference" on the form "frmTRANSCP"?

Forms!frmTRANSCP!Reference.DefaultValue = Forms!frmTRANSCP!Reference
 
What about this ?
Code:
Me!Reference.DefaultValue = "'" & Me!Reference.Value & "'"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV

Yeh, that did it - thanks very much. I can set all the relevant fields that way.

Terry
 
How are ya TerryEA . . .

The following allows you to set defaults to any record by double clicking the record selector for that record.

[ol][li]Put a question mark [blue]?[/blue] in the [blue]Tag[/blue] property of the textboxes of interest.[/li]
[li]In the [blue]forms On Dbl Click[/blue] event copy/paste the following:
Code:
[blue]   Dim ctl As Control, DQ As String
   
   DQ = """"
   
   If Not Me.NewRecord Then
      For Each ctl In Me.Controls
         If ctl.Tag = "?" Then
            ctl.DefaultValue = DQ & ctl & DQ
         End If
      Next
   End If[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hi TheAceMan1

Neat! - I follow that.

I didn't know you could step through all the controls on a form in that way. It's not what I needed on this occasion, since once records are entered and saved they won't be changed in this application. I just needed something to save the user time on data entry with new records, where much of the input was repetitive.

However, your routine shows just how control properties can be used and how to you can automatically set values, at the click of the mouse. I can see many applications for that. I save snippets of code like that for future use. Much appreciated. Thanks to all the help from you guys recently, my accounts application is looking pretty solid.

Thanks again

Terry
 
A different flavour of the same ice-cream:
Instead of:
If ctl.Tag = "?" Then

You could use:
If ctl.BackColor = CON_GETDEFAULT Then

where CON_GETDEFAULT is a public constant, declared in a module, holding the number of a specific colour. If the control has that back colour, it gets the default value.

This way you can save the Tag property for other purposes, such as holding information about the control at run-time, variable row sources for combo/list boxes and other goodies...

HTH



[pipe]
Daniel Vlas
Systems Consultant

 
Hi danvlas

Clever. I'm full of admiration for the gurus here. Some of the solutions are downright ingenious.

Cheers

Terry
 
Hello TerryEA,

How about Ctrl + ' (control + apostrophe) to copy the value of the previous record (per field)

'Hope this helps
 
Hi JohnPatrickPH

I tried your suggestion but it didn't work - I added a record, validated it and saved it with a command button and then, whilst adding a new record immediatetly, I typed CTRL and apostrophe immediatetly on getting the focus on a field I wanted to copy. Is that what you meant? Your suggestion certainly souds like the simplest solution.

Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top