Can't go to control

B

BHawkins

To make things short, here is what I am trying to get access to do.

I want it to copy a value from one record and then go to the next record in
the same form and paste it in a different field. Then go back to the previous
record, copy another value from a combo box, return to the next record in the
same form and paste it in a second combo box.

What is happening is that it works fine when going to a text box (the first
record), but when it is supposed to copy from the combo box, the error
message come up that it can't set the focus on the combo box.

Does anyone have any ideas?
 
A

Allen Browne

Forms have a RecordsetClone for this purpose. The clone set can be at a
different record (the old one), while you write the values into the new
record.

This kind of thing:

Private Sub cmdDuplicate()
Dim rs As DAO.RecordsetClone

If Me.Dirty Then 'Save any changes first.
Me.Dirty = False
End If
If Me.NewRecord Then 'Make sure there is a record.
MsgBox "Select a record to duplicate."
Else
'Set the clone set to the old record.
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark

'Move the form to the new record.
RunCommand acCmdRecordsGotoNew

'Copy the values from the old one to the new one
Me.[Text1] = rs![SomeField]
Me.[AnotherControlNameHere] = rs![SomeOtherField]
'and so on.
End If

Set rs = Nothing
End Sub
 
B

BHawkins

I've only been working with Access for a couple of years and have never had a
reason to read on cloning. I guess this is as good a time as any to start.

Thanks for your help. It is greatly appreciated.




Allen Browne said:
Forms have a RecordsetClone for this purpose. The clone set can be at a
different record (the old one), while you write the values into the new
record.

This kind of thing:

Private Sub cmdDuplicate()
Dim rs As DAO.RecordsetClone

If Me.Dirty Then 'Save any changes first.
Me.Dirty = False
End If
If Me.NewRecord Then 'Make sure there is a record.
MsgBox "Select a record to duplicate."
Else
'Set the clone set to the old record.
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark

'Move the form to the new record.
RunCommand acCmdRecordsGotoNew

'Copy the values from the old one to the new one
Me.[Text1] = rs![SomeField]
Me.[AnotherControlNameHere] = rs![SomeOtherField]
'and so on.
End If

Set rs = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

BHawkins said:
To make things short, here is what I am trying to get access to do.

I want it to copy a value from one record and then go to the next record
in
the same form and paste it in a different field. Then go back to the
previous
record, copy another value from a combo box, return to the next record in
the
same form and paste it in a second combo box.

What is happening is that it works fine when going to a text box (the
first
record), but when it is supposed to copy from the combo box, the error
message come up that it can't set the focus on the combo box.

Does anyone have any ideas?
 
Top