1. That command button needs to be on the main form
2. The quotation marks before !Project Name and after Me.Project Manager
should not be there, remove them.
3. You have broken one of the ten commandments of Access by putting spaces
in your field names. As a result you will now need to enclose the field
names in square brackets e.g.
![Project Name] = Me.[Project Name]
http://www.mvps.org/access/tencommandments.htm
Here is the code that I'm using for the command button. I motified from
Mr.
Allen Browne web page on tips for advance access users. I'm trying to fix
the error in it but Access freezes up everytime I tried to fix the
problem.
Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
" !Project Name = Me.Project Name
!FHA Number = Me.FHA Number
!Project Manager = Me. Project Manager"
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !OrderID
'Duplicate the related records: append query.
If
Me.[F_sub_FinancialDataSubform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [F_sub_FinancialData]
(Mnth/YrFormSent, DateReceived, Excess Income Earned in Excess of Basic
Rents, Excess Income Retained (Project), Excess Income owed to HUD, Paid
to
HUD, Number of Check Received,FHA_Num ) " & _
"SELECT " & lngID & " As NewID, Mnth/YrFormSent,
DateReceived, Excess Income Earned in Excess of Basic Rents, Excess Income
Retained (Project), Excess Income owed to HUD, Paid to HUD, Number of
Check
Received,FHA_Num " & _
"FROM [F_sub_FinancialData] WHERE FHA_Num = " &
Me.FHA_Num & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
End If
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdDupe_Click"
Resume Exit_Handler
End Sub
The quotation marks around the part of the code after Add new is marked in
red in the VBA screen. I went fix it but it keeps frezzing and closing on
me. Please let me know what I'm doing wrong. I haven't been able to
figure
it out.
thanks, Keri
:
It depends entirely on what you want it to do.
I have a command button that I'm using for my form and subform. Mr.
Allen
Brown was very nice to have one posted in his tips section on his
webpage.
I
have a question does the command button go on the form or the subform.
I
cannot get it to work?
Thanks,
Keri