Clueless Newbie
Immortal. So far.
- Local time
- Today, 16:46
- Joined
- Feb 6, 2004
- Messages
- 48
I'm currently using the function below (thank you, Mile-O-Phile!
) in order to duplicate a current record with the click of one button. What I would also like to do is to not duplicate but change the value of just one single field ("xyz") during that duplication process.
I assume that theoretically I should open a some sort of input box, ask the user to type in the new value for "xyz", save that to a temporary variable and stick the latter into my record duplicate -- while the original record is left untouched. The only problem is: I'm not sure whether I'm even aiming in the right direction with this kind of solution. In case I am, how does one implement this? Everything I've tried so far has only resulted in messing up the function.
Here's the "pure duplication" code I have so far; any help with the above-mentioned add-on would be most appreciated. Thank you!
Ute

I assume that theoretically I should open a some sort of input box, ask the user to type in the new value for "xyz", save that to a temporary variable and stick the latter into my record duplicate -- while the original record is left untouched. The only problem is: I'm not sure whether I'm even aiming in the right direction with this kind of solution. In case I am, how does one implement this? Everything I've tried so far has only resulted in messing up the function.

Here's the "pure duplication" code I have so far; any help with the above-mentioned add-on would be most appreciated. Thank you!

Ute
Code:
Public Function Duplicate(ByVal strKey As String, ByVal strTable As String, _
ByVal lngID As Long) As Long
On Error GoTo Err_Duplicate
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim varValue As Variant
Set db = CurrentDb
Set rs = db.OpenRecordset(strTable)
With rs
.AddNew
For Each fld In rs.Fields
If fld.Name <> strKey Then
varValue = DLookup("[" & fld.Name & "]", strTable, "[" & strKey & "] = " & lngID)
If Not IsNull(varValue) Then
fld = varValue
End If
Else
Duplicate = DMax("[" & strKey & "]", strTable) + 1
fld = Duplicate
End If
Next
.Update
.Close
End With
'Duplicate = True
Exit_Duplicate:
Set fld = Nothing
Set rs = Nothing
Set db = Nothing
Exit Function
Err_Duplicate:
Duplicate = False
Resume Exit_Duplicate
End Function
Last edited: