Dim stFieldA As string, stFieldB As String, stFieldC As String  ' Assuming they 
are all strings
Dim stSQL As String

'Hold the current data in the variables
stFieldA = Me.FieldA
stFieldB = Me.FieldB
stFieldC = Me.FieldC

'FIRST METHOD
'Go to a new record and paste the contents of the variables into the 
appropriate fields
DoCmd.GoTo Record, , acNewRec
Me.FieldA = stFieldA
Me.FieldB = stFieldB
Me.FieldC = stFieldC

SECOND METHOD
'Run a query
stSQL = "INSERT INTO FieldTable(FieldA, FieldB, FieldC) SELECT " & Chr(34) & 
stFieldA & Chr(34) & ", "
stSQL = stSQL & Chr(34) & stFieldB & Chr(34) & ", " & Chr(34) & stFieldC & 
Chr(34) & ";"
DoCmd.RunSQL stSQL

NOTES: 
  1..  FieldTable is the name of the table. 
  2.. As I mentioned earlier on the second method may fail if one of the three 
fields is a primary key. 
  3.. Chr(34) inserts double quotes
Good luck

Liveson

  ----- Original Message ----- 
  From: Arnaldo Ferrari Nasi 
  To: [email protected] 
  Cc: [EMAIL PROTECTED] 
  Sent: Tuesday, October 18, 2005 10:14 AM
  Subject: Re: newbie - duplicating the current record



  Hi Liveson,

  >1. Create variables to hold the current data on the form.
  >2. Go to the new record: DoCmd.GoToRecord , , acNewRec
  >3. Paste the data held in the variables into the textboxes on the form

  Can you give me the exact and complete code to do these actions?
  (columns in the table are FieldA, FieldB and FieldC)

   > The other way is to use an append query which should append the current 
  record >into the record source

  I am not able to tell it to use only the current record... if I use this 
  way it appends each time all the records in te table...

  Thanks
  Arnaldo.


  >Arnaldo
  >There might be a better way of achieving your goal but I think the 
  >following simple method may also assist in some way. Place a command 
  >button with the label "Copy" or anything meaningful on your form. In the 
  >OnClick event of this button do the following
  >
  >1. Create variables to hold the current data on the form.
  >2. Go to the new record: DoCmd.GoToRecord , , acNewRec
  >3. Paste the data held in the variables into the textboxes on the form
  >
  >You can now edit your data before saving the record. The new record is not 
  >saved until you move away from it or close the form so you have a chance 
  >of changing the primary key. The other way is to use an append query which 
  >should append the current record into the record source and then after 
  >refreshing the form go to the end of the record set to view the appended 
  >record but the problem lies with the primary key if there is one. Unless 
  >you change the primary key before appending the record the query will fail.
  >
  >Good luck
  >Liveson
  >
  >
  > > Hi List,
  > >
  > > I am working with an input form. I use this form to browse data too.
  > > When I see an interesting record I want to duplicate it automatically and
  > > change some data.
  > > I think that I can do this with a query but I don't know how.
  > > I also can use the menu' for selecting the current record>copying in the
  > > clipboard>appending it in the end of the table. But I want to do this with
  > > only one action, so I need to create a routine in VBA. I don't know the
  > > right code and Access has not a macro recorder like Excel...
  > > Anyone can help me?
  > >
  > > TIA
  > > Arnaldo.




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/q7folB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ms_access/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




Reply via email to