Question

Duplicate record not working access 2003

Asked by: LadyHagood

have an acces database.  have a form. this form is used to add reference docs.  there are three fields on form : DocumentClass, DocumentName, Hyperlink (using a browse button also located on the form).  There is also a subform of the table to which all of this is linked, giving the user viewability to the docs that are already in the system.  Problem is, after he three text boxs are populated by the user, I hit a "save" button.  this button says save, but it actually duplicate the record and clears the documentname and hyperlink fields leaving the class populated and ready for the user to enter more.  However, after using hte "save" button a couple of times, I get an error or "Paste/Append" isn't available now. ideas?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-04 at 13:37:36ID24872616
Topics

Microsoft Access Database

,

Access Forms

,

Access Coding/Macros

Participating Experts
2
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Help Duplicate Subform Records in 2000
    I have a Duplicate button on the toolbar of frmTempJobOrder which runs this function: Function DuplicateTemp() On Error GoTo Err_DuplicateTemp Dim Msg, Style, Response Dim w1 As Workspace, db1 As Database, qd1 As QueryDef, fSuccess As Long Dim fTrans As ...
  2. Hyperlinks duplicated on resave
    I used the excellent answer to the following question to automatically create hyperlinks for websites and emails in a textarea http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20663785.html This works fine when the user FIRST saves the record. However when th...
  3. Unable to edit hyperlink in Subform
    I've created a form that lists the version of an application. I also created a subform that has a record of each change that was made to a version. In the underlying table of the subform, I've set one of the fields as a hyperlink. When I open only the subform, I can edit t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GrahamMandenoPosted on 2009-11-04 at 14:42:11ID: 25744868

Hi LadyHagood

Could you please post the code attached to your Save button's Click event?

I suspect there is a much better way to do this that copy/paste.

--
Graham

 

by: Helen_FeddemaPosted on 2009-11-04 at 15:22:49ID: 25745237

All you need for a save is this line:
DoCmd.RunCommand acCmdSaveRecord

 

by: LadyHagoodPosted on 2009-11-05 at 05:18:29ID: 25749061

In the code, I am duplicating and clearing two of the fields. this allows the user to keep entering while automatically saving the record at thesame time.

On Error GoTo Err_Command20_Click
 
 
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
 
DocumentName.Value = Null
Text9.Value = Null
 
Exit_Command20_Click:
    Exit Sub
 
Err_Command20_Click:
    MsgBox Err.Description
    Resume Exit_Command20_Click

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

Select allOpen in new window

 

by: Helen_FeddemaPosted on 2009-11-05 at 08:33:45ID: 25751169

Do you mean that you are copying the values of some fields to the new record?  You can do this using code such as the sample below (and BTW, you are using some very old -- circa Access 95 -- syntax, probably from Microsoft Wizards, which haven't been updated for many years).

Private Sub cmdCopyandNew_Click()
 
   Dim strLastName As String
   Dim strFirstName As String
   
   strLastName = Nz(Me![txtLastName].Value)
   strFirstName = Nz(Me![txtFirstName].Value)
   DoCmd.RunCommand acCmdSaveRecord
   DoCmd.GoToRecord Record:=acNewRec
   Me![txtLastName].Value = strLastName
   Me![txtFirstName].Value = strFirstName
   
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: Helen_FeddemaPosted on 2009-11-05 at 08:36:55ID: 25751211

For a more sophisticated Copy Record situation, where there are many fields to copy and some not to copy, you can use the Tag property of controls on a form to determine which will be copied and which not copied.  (The first sample is for a simple situation -- it might work for you.)  Here is some code for copying records:

Simple version -- OK if there is no AutoNumber or other key field in the record source
 
   DoCmd.RunCommand acCmdSelectRecord
   DoCmd.RunCommand acCmdCopy
   DoCmd.RunCommand acCmdPasteAppend
 
This one works with any record source -- put "No Copy" in the Tag property of the controls whose values should not be copied.
 
It is called from a command button on a form, like this:
 
   Call CopyRecord(Me)
 
Public Sub CopyRecord(frm As Access.Form)
'Created by Helen Feddema 26-Sep-2009
'Last modified 26-Sep-2009
 
On Error GoTo ErrorHandler
 
   Dim CopyFields() As Variant
   
   lngCount = CountControls(frm)
   Debug.Print "Number of controls to copy: " & lngCount
   
   'Redimension array with actual number of controls to copy
   ReDim CopyFields(lngCount - 1, 1)
   
   'Cycle through all controls on form Detail section (except those
   'marked "No Copy") and save to an array
   lngCount = 0
   lngArrayNo = 0
   
   For Each ctl In frm.Section(acDetail).Controls
      strControlName = ctl.Name
      Debug.Print "Control name: " & strControlName _
         & "; tag: " & ctl.Tag
         
      If InStr(ctl.Tag, "No Copy") = 0 Then
      
         'Check field type and skip those that don't have values
         Debug.Print "Control name: " & strControlName
         lngControlType = ctl.ControlType
         
         Select Case lngControlType
            'Controls with values
            Case acTextBox
               Debug.Print "Control source: " & ctl.ControlSource
               GoTo Copy
            
            Case acComboBox
               GoTo Copy
            
            Case acCheckBox
               GoTo Copy
            
            Case acBoundObjectFrame
               GoTo Copy
               
            Case acListBox
               GoTo Copy
           
            Case acOptionGroup
               GoTo Copy
            
            Case acOptionButton
               'Check for control source, and only copy from
               'option buttons with one (bound option buttons)
               strTest = ctl.ControlSource
               GoTo Copy
               
            Case Else
               'No Value property; nothing to copy
               GoTo NoCopy
         End Select
Copy:
         strFieldName = ctl.ControlSource
         varFieldValue = ctl.Value
         Debug.Print strFieldName & " value: " & varFieldValue
         CopyFields(lngArrayNo, 0) = strFieldName
         CopyFields(lngArrayNo, 1) = varFieldValue
         lngArrayNo = lngArrayNo + 1
         lngCount = lngCount + 1
NoCopy:
      End If
   Next ctl
 
   Debug.Print "Number of controls to copy: " & lngCount
   
   'Create recordset, add a new record, and copy data to it from array
   Set dbs = CurrentDb
   strTable = "Pharmacy Scheduling"
   
   Set rst = dbs.OpenRecordset(strTable, dbOpenDynaset)
   With rst
      .AddNew
      For lngArrayCount = 0 To lngCount - 1
         Debug.Print "Processing row " & lngArrayCount
         strFieldName = CopyFields(lngArrayCount, 0)
         varFieldValue = CopyFields(lngArrayCount, 1)
         Debug.Print "Field name: " & strFieldName
         Debug.Print "Field value: " & varFieldValue
         If strFieldName <> "" Then
            .Fields(strFieldName) = varFieldValue
         End If
      Next lngArrayCount
      .Update
      .Close
   End With
      
   'Requery form and go to new record
   frm.Requery
   DoCmd.GoToRecord objecttype:=acDataForm, _
      objectname:=frm.Name, _
      record:=acLast
   
ErrorHandlerExit:
   Exit Sub
 
ErrorHandler:
   If Err.Number = 2455 Then
      'Unbound option button
      Resume NoCopy
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " & _
         Err.Description
      Resume ErrorHandlerExit
   End If
 
End Sub
 
Public Function CountControls(frm As Access.Form) As Long
'Created by Helen Feddema 26-Sep-2009
'Last modified 26-Sep-2009
 
On Error GoTo ErrorHandler
   
   'Cycle through all controls on form Detail section (except those
   'marked "No Copy") and determine number of controls to copy
   lngCount = 0
   strTest = ""
   
   For Each ctl In frm.Section(acDetail).Controls
      strControlName = ctl.Name
      'Debug.Print "Control name: " & strControlName
      
      If InStr(ctl.Tag, "No Copy") = 0 Then
      
         'Check field type and skip those that don't have values
         lngControlType = ctl.ControlType
         
         Select Case lngControlType
            'Controls with values
            Case acTextBox
               GoTo CountCtl
            
            Case acComboBox
               GoTo CountCtl
            
            Case acCheckBox
               GoTo CountCtl
            
            Case acBoundObjectFrame
               GoTo CountCtl
               
            Case acListBox
               GoTo CountCtl
           
            Case acOptionGroup
               GoTo CountCtl
            
            Case acOptionButton
               'Check for control source, and only count
               'option buttons with one (bound option buttons)
               strTest = ctl.ControlSource
               If strTest <> "" Then
                  GoTo CountCtl
               End If
               
            Case Else
               'No Value property; don't count
               GoTo NoCount
         End Select
         
CountCtl:
         lngCount = lngCount + 1
NoCount:
      End If
   
      strTest = ""
   Next ctl
 
   Debug.Print "Number of controls to copy: " & lngCount
   CountControls = lngCount
   
ErrorHandlerExit:
   Exit Function
 
ErrorHandler:
   If Err.Number = 2455 Then
      'Unbound option button
      Resume NoCount
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " & _
         Err.Description
      Resume ErrorHandlerExit
   End If
 
End Function
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:

Select allOpen in new window

 

by: GrahamMandenoPosted on 2009-11-05 at 13:05:18ID: 25754018

Hi LadyHagood

Thanks for posting your code.  

As Helen has pointed out, any code that uses DoMenuItem is very old and should be avoided.  A clue here is the "acMenuVer70", which refers to the menu structure of Access V7.0 (aka Access 95).  Access 95 was about the worst version ever released, and we are now up to Access V14!!

The fact that the wizards still generate Access 95 code says a lot about why most of us who have been around for a while would never use a wizard :-)

I've attached below an alternative function you might like to consider for the general-purpose copying of records.  It has certain advantages - for example, because it works on fields, not controls, it will copy fields that are in your recordsource but not bound to controls on your form.  It also doesn't need to bother with distinguishing between bound and unbound controls.

It will automatically skip autonumber fields and fields that are not updatable (e.g. calculated fields in your query), and you can provide an optional list of other fields to skip, so you don't need to mess about with tags.

Just call it like this:

Call fm_CloneRecord( Me, "DocumentName", "OtherField" )

...where OtherField is the one bound to Text9.

(By the way, I strongly recommend you adopt the practice of giving controls meaningful names as soon as you add them to your form.  Names such as Text9 and Command20 mean nothing and do not help you to write your code!)

In fact, if calling the function is the only thing you want the Click event to do, you could dispense with the event procedure and call it directly from the OnClick property:

=fm_CloneRecord( [Form], "DocumentName", "OtherField" )

Good luck!
--
Graham

Public Function fm_CloneRecord( _
    frm As Form, _
    ParamArray SkipFields() _
  ) As Boolean
Dim rsCurrent As DAO.Recordset
Dim fld As DAO.Field
Dim i As Integer
On Error GoTo ProcErr
  ' save current record if necessary
  If frm.Dirty Then frm.Dirty = False
  Set rsCurrent = frm.RecordsetClone
  rsCurrent.Bookmark = frm.Bookmark
  frm.Recordset.AddNew
  For Each fld In rsCurrent.Fields
    ' skip if AutoNumber
    If (fld.Attributes And dbAutoIncrField) <> 0 Then GoTo NextField
    ' skip if not Updatable
    If (fld.Attributes And dbUpdatableField) = 0 Then GoTo NextField
    ' skip if in out skip list
    For i = 0 To UBound(SkipFields)
      If fld.Name = SkipFields(i) Then GoTo NextField
    Next
    frm(fld.Name) = fld
NextField:
  Next fld
  fm_CloneRecord = True
ProcEnd:
  On Error Resume Next
  Exit Function
ProcErr:
  MsgBox "Error #" & Err.Number & " cloning record" _
    & vbCrLf & vbCrLf & Err.Description
  Resume ProcEnd
End Function

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: Helen_FeddemaPosted on 2009-11-05 at 14:22:50ID: 25754736

Yes, Access 95 was definitely a skipper -- I didn't use it except as needed to co-author a book on the Access 95 Certification exam.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...