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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform in opening in add mode wont open on new record?

Status
Not open for further replies.

maxxev

Technical User
Jul 17, 2008
139
NL


Hi I have a form with a Sub form that is a continous form, on this sub form there is a button that should allow users to add a country of origin for an ingredient, I have copied and pasted code and modified it to fit to open the form showing any exisiting info and a new line, or open it in add mode if nothing exisiting.

However when there is no existing info the form states "you can't assign a value to this object".

Any thought please?

Cheers

Code:
Private Sub Sub_Comp_Ing_COO_Click()
On Error GoTo Err_Sub_Comp_Ing_COO_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "S_frmSubComponents_in_Components"
    
    If IsNull(DLookup("SubComp_in_ingID", "tblSubComp_COO", "SubComp_in_ingID=" & Me![SubComp_in_ingID])) Then
    DoCmd.OpenForm "frmSubComp_COO", , , , acFormAdd
    Forms!frmRMIngDeclaration!S_frmSubComponents_in_Components.Form.SubComp_in_ingID = Me![SubComp_in_ingID]

Else
    DoCmd.OpenForm "frmSubComp_COO", , , "SubComp_in_ingID=" & Me![SubComp_in_ingID]
End If
Exit_Sub_Comp_Ing_COO_Click:
    Exit Sub

Err_Sub_Comp_Ing_COO_Click:
    MsgBox Err.Description
    Resume Exit_Sub_Comp_Ing_COO_Click
    
End Sub
 
I've just spotted my stupidity on this please ignore.

However anyone got any thoughts as to this issue:

The form now opens up with 2 blank rows, presuming that you are going to fill one in, however is there anyway for the code to delete the new record on closing if it is left blank? (my code for the table states that a country HAS to be entered into a field, so preferebly before this warning/error comes up?)

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top