Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Works / Subform Doesn't

Status
Not open for further replies.

drewcp

Programmer
Jul 31, 2008
30
US
I have a form that i have set as a subform

Here is my form

form.bmp


And here it is set as a subform

subform.bmp


What my problem deals with is my duplicate record button on my subform (uses the new record icon)

The new record button has the following code (as a macro) on the event "on click"

Code:
'------------------------------------------------------------
' Macro11
'
'------------------------------------------------------------
Function Macro11()
On Error GoTo Macro11_Err

    With CodeContextObject
        DoCmd.SetProperty "RATE_OVERIDE", acPropertyEnabled, "1"
        DoCmd.SetProperty "ZONE", acPropertyEnabled, "1"
        DoCmd.SetProperty "TAX_RATE", acPropertyEnabled, "1"
        DoCmd.SetProperty "NBHD_CODE", acPropertyEnabled, "1"
        DoCmd.SetProperty "NBHD_GROUP", acPropertyEnabled, "1"
        DoCmd.SetProperty "LINK_ID", acPropertyEnabled, "1"
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.SetProperty "RECID1", acPropertyEnabled, "0"
        DoCmd.SetProperty "Combo35", acPropertyEnabled, "0"
        DoCmd.SetProperty "Combo37", acPropertyEnabled, "0"
        DoCmd.SetProperty "Combo39", acPropertyEnabled, "0"
        DoCmd.SetProperty "ACRES", acPropertyEnabled, "0"
        DoCmd.SetProperty "NUM_LOTS", acPropertyEnabled, "0"
        On Error Resume Next
        DoCmd.RunCommand acCmdSelectRecord
        If (.MacroError = 0) Then
            DoCmd.RunCommand acCmdCopy
        End If
        If (.MacroError = 0) Then
            DoCmd.RunCommand acCmdRecordsGoToNew
        End If
        If (.MacroError = 0) Then
            DoCmd.RunCommand acCmdSelectRecord
        End If
        If (.MacroError = 0) Then
            DoCmd.RunCommand acCmdPaste
        End If
        If (.MacroError <> 0) Then
            Beep
            MsgBox .MacroError.Description, vbOKOnly, ""
        End If
        DoCmd.SetProperty "RECID1", acPropertyEnabled, "1"
        DoCmd.SetProperty "Combo35", acPropertyEnabled, "1"
        DoCmd.SetProperty "Combo37", acPropertyEnabled, "1"
        DoCmd.SetProperty "Combo39", acPropertyEnabled, "1"
        DoCmd.SetProperty "ACRES", acPropertyEnabled, "1"
        DoCmd.SetProperty "NUM_LOTS", acPropertyEnabled, "1"
        DoCmd.SetProperty "RATE_OVERIDE", acPropertyEnabled, "0"
        DoCmd.SetProperty "ZONE", acPropertyEnabled, "0"
        DoCmd.SetProperty "TAX_RATE", acPropertyEnabled, "0"
        DoCmd.SetProperty "NBHD_CODE", acPropertyEnabled, "0"
        DoCmd.SetProperty "NBHD_GROUP", acPropertyEnabled, "0"
        DoCmd.SetProperty "LINK_ID", acPropertyEnabled, "0"
        DoCmd.GoToControl "RECID1"
    End With


Macro11_Exit:
    Exit Function

Macro11_Err:
    MsgBox Error$
    Resume Macro11_Exit

End Function

I know that this is probably a weird way to do this, but since i could only have certain fields copied out of the record this was the only way i could come up with.

When i open my form by itself it works perfect. it creates a new record with all of the fields that i want and none of the ones that i do not.

When i run it as a subform though, it brings up the following error message.

error.bmp


and this is the macro Action Failed box that comes up after

macro%20error.bmp


I have changed it to make sure that everything is visible, i have changed it to visual basic, i have added code to make sure that the subform has focus, and i am now at a total loss

Does anyone know what could be wrong with this?

Thanks in advance
 
Nevermind on this, i figured it out

what i did was to create an append query that would only append the fields that i needed and then requeried my form to reflect the new record added on my table/query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top