How do I code for function in subforms?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form and a subform. The form is bound to a table and the subform to
another table.

I have two buttons that I am trying to code and having troubles:
Duplicate Record (in Subform)
Delete record (in Subform)
 
What is the problem?

Before running this code, have you set the focus to the sub form?

Me.[SubFormControlName].SetFocus
Your code
 
I tried that and it's not working.

For NEW I have

Private Sub New_Insurance_Contact_Click()
On Error GoTo Err_New_Insurance_Contact_Click

Me.[Insurance Contacts Subform].SetFocus
DoCmd.GoToRecord , , acNewRec

Exit_New_Insurance_Contact_Click:
Exit Sub

Err_New_Insurance_Contact_Click:
MsgBox Err.Description
Resume Exit_New_Insurance_Contact_Click

End Sub

and the error is "Microsoft Access cannot find the field "|" eferred to in
your expression."

Ofer Cohen said:
What is the problem?

Before running this code, have you set the focus to the sub form?

Me.[SubFormControlName].SetFocus
Your code

--
Good Luck
BS"D


Christian > said:
I have a form and a subform. The form is bound to a table and the subform to
another table.

I have two buttons that I am trying to code and having troubles:
Duplicate Record (in Subform)
Delete record (in Subform)
 
For DELETE I have

Private Sub Delete_Insurance_Contact_Click()
On Error GoTo Err_Delete_Insurance_Contact_Click

Me.[Insurance Contacts Subform].SetFocus
RunCommand acCmdDeleteRecord

Exit_Delete_Insurance_Contact_Click:
Exit Sub

Err_Delete_Insurance_Contact_Click:
MsgBox Err.Description
Resume Exit_Delete_Insurance_Contact_Click

End Sub

The error I get is "Microsoft Access cannot find the field "|" referred to
in your expression.

Ofer Cohen said:
What is the problem?

Before running this code, have you set the focus to the sub form?

Me.[SubFormControlName].SetFocus
Your code

--
Good Luck
BS"D


Christian > said:
I have a form and a subform. The form is bound to a table and the subform to
another table.

I have two buttons that I am trying to code and having troubles:
Duplicate Record (in Subform)
Delete record (in Subform)
 
The name [Insurance Contacts Subform] is it the name of the sub form, or the
name of the control in the main form that contain the sub form?

It need to be the name of the control and not the name of the form itself.

--
Good Luck
BS"D


Christian > said:
For DELETE I have

Private Sub Delete_Insurance_Contact_Click()
On Error GoTo Err_Delete_Insurance_Contact_Click

Me.[Insurance Contacts Subform].SetFocus
RunCommand acCmdDeleteRecord

Exit_Delete_Insurance_Contact_Click:
Exit Sub

Err_Delete_Insurance_Contact_Click:
MsgBox Err.Description
Resume Exit_Delete_Insurance_Contact_Click

End Sub

The error I get is "Microsoft Access cannot find the field "|" referred to
in your expression.

Ofer Cohen said:
What is the problem?

Before running this code, have you set the focus to the sub form?

Me.[SubFormControlName].SetFocus
Your code

--
Good Luck
BS"D


Christian > said:
I have a form and a subform. The form is bound to a table and the subform to
another table.

I have two buttons that I am trying to code and having troubles:
Duplicate Record (in Subform)
Delete record (in Subform)
 
That fixed it! I'm such a dork... thanks!!! |)

Ofer Cohen said:
The name [Insurance Contacts Subform] is it the name of the sub form, or the
name of the control in the main form that contain the sub form?

It need to be the name of the control and not the name of the form itself.

--
Good Luck
BS"D


Christian > said:
For DELETE I have

Private Sub Delete_Insurance_Contact_Click()
On Error GoTo Err_Delete_Insurance_Contact_Click

Me.[Insurance Contacts Subform].SetFocus
RunCommand acCmdDeleteRecord

Exit_Delete_Insurance_Contact_Click:
Exit Sub

Err_Delete_Insurance_Contact_Click:
MsgBox Err.Description
Resume Exit_Delete_Insurance_Contact_Click

End Sub

The error I get is "Microsoft Access cannot find the field "|" referred to
in your expression.

Ofer Cohen said:
What is the problem?

Before running this code, have you set the focus to the sub form?

Me.[SubFormControlName].SetFocus
Your code

--
Good Luck
BS"D


:

I have a form and a subform. The form is bound to a table and the subform to
another table.

I have two buttons that I am trying to code and having troubles:
Duplicate Record (in Subform)
Delete record (in Subform)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top