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!

copy current form data to new record 1

Status
Not open for further replies.

JOD59

Technical User
Dec 17, 2003
39
US
Does anyone know how to copy the current Form record data in to a new record. I would also like to clear some of the fields in the new record. This will save the person inputing from having to retype information.
 
Howare ya JOD59 . . . . .

In the [blue]BeforeUpdate[/blue] event of the form, set the [purple]DefaultValue[/purple] property of the controls of interest:
Code:
[blue]   Me![purple][b]TextboxName[/b][/purple].DefaultValue = Me![purple][b]TextboxName[/b][/purple][/blue]

Calvin.gif
See Ya! . . . . . .
 
Aceman Thanks for the quick reply, but I don't think I was real clear in my earlier post. What I would like to do is copy all the contents of the current form to a new record but I need to clear a few fields when I do so. Here is the code I have tried but it has one problem. It clears the data in the current record as well. I can't seem to figure this one out. thanks for any help.
 
oops forgot to include the code!!!!

Private Sub cmdDupRecord_Click()
On Error GoTo Err_cmdDupRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_cmdDupRecord_Click:
Exit Sub
Me.cboDateComplete.Value = 0
Me.tblChargeNo.Value = Null
Me.tblSBSNo.Value = Null

Err_cmdDupRecord_Click:
MsgBox Err.Description
Resume Exit_cmdDupRecord_Click

End Sub
 
JOD59 . . . . .

As far as a new record is concerned, [blue]you only need to copy those values you want transferred[/blue] (other fields remain blank).

Assigning values to the [purple]DefaultValue[/purple] gives you the advantage of not triggering [purple]Edit Mode![/purple]

Calvin.gif
See Ya! . . . . . .
 
The default is not an option because the information may be different depending on the user. As projects change the default information will change.
 
JOD59 . . . .

Understood!

Since your already using a commmand button, how about this . . .

The command button will have two modes:
[ol][li]Button Caption is [purple]Lock Repeat Record[/purple] (by default):
[ol a][li]user will [blue]select the record to be copied[/blue], then hit the button.[/li]
[li]The ID of the record will be [blue]held in memory[/blue] for updating New Records [purple]as long as this mode is enabled.[/purple][/li]
[li]Everytime the focus is moved to a new record, [blue]defaults are set!.[/blue][/li]
[li]The Caption of the button is changed to [purple]No Repeat Record[/purple] (the alternate mode).[/li][/ol][/li]
[li]Button Caption is [purple]No Repeat Record[/purple]:
[ol a][li]User hits the button and the [purple]Defaults are are permanently removed[/purple].[/li]
[li]The Caption of the button is changed to [purple]Lock Repeat Record[/purple].[/li][/ol][/li][/ol]
I believe this gives you more of the automation you seek, espcially since the user doesn't have to go back to that record each time to get a repeat/copy.

BTW, I didn't check you code, but if you move Exit Sub afrer the null settings it should work provided the rest of your code is ok.

[blue]So . . . . your thoughts?[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan, that seems like the best way to go. I like the Idea of changing the defaults. I'll give it a try
 
JOD59 . . . . .

Sorry I couldn't get back to ya last night.

Anyway try the following . . .
[ol][li]In the Tag property of each control you wish to repeat, enter [purple]?[/purple] .[/li]
[li]Replace your button code with the following ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim ctl As Control, DQ As String
   Dim Repeat As Boolean, errRepeat As Boolean
   Dim Msg As String, Style As Integer, Title, DL As String
   
   DQ = """"
   DL = vbNewLine & vbNewLine
   Repeat = (Me![purple][b]ButtonName[/b][/purple].Caption = "Lock Repeat Record")
   errRepeat = (Me.NewRecord Or Me.Dirty)
   
   If Repeat And errRepeat Then
      Msg = "Can't Repeat a New or Currently Edited Record!" & DL & _
            "Select a currently saved record or" & DL & _
            "Save the record your currently editing." & DL & _
            "Then try again . . ."
      Style = vbInformation + vbOKOnly
      Title = "Can't Repear Error . . ."
      MsgBox Msg, Style, Title
   Else
      If Repeat Then
         Me![purple][b]ButtonName[/b][/purple].Caption = "No Repead Record"
      Else
         Me![purple][b]ButtonName[/b][/purple].Caption = "Lock Repeat Record"
      End If
      
      For Each ctl In Me.Controls
         If ctl.Tag = "[b]?[/b]" Then
            If Repeat Then
               ctl.DefaultValue = DQ & ctl & DQ
            Else
               ctl.DefaultValue = ""
            End If
         End If
      Next
   
   End If[/blue]
[/li][/ol]
If comboboxes are included you may/maynot have a problem.

[purple]Thats it . . . give it a whirl and let me know . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top