OpenForm Action Cancelled

K

Kevin Sprinkel

On an unbound form, a user selects a project, and enters a
starting default value. A command button then opens a
data entry form based on tblProjects, with a subform
sbfDuctTakeoff, linked on the JobNumber, and the entered
default is set for one of the subform fields.

Clicking the command button generates the error: "The
OpenForm method was cancelled." I thought that it might
be because the recordset was empty, and that I need to
check for that condition, but it doesn't open for projects
that definitely have records. The data entry form will
open manually and display all records correctly.

Can anyone find where I've gone wrong?

The command button code is:

Private Sub cmdOpenfrmDuctTakeoff_Click()
On Error GoTo Err_cmdOpenfrmDuctTakeoff_Click

Dim stDocName As String
Dim stLinkCriteria As String

' Open form
stDocName = "frmDuctTakeoff"
stLinkCriteria = "[JobNumber]=" & Me![cboJobNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria

'Set default value
Forms!frmDuctTakeoff!sbfDuctTakeoff.Form! _
txtDwgRef.DefaultValue = Me!txtInitialDwgRef

' Close project selection form
DoCmd.Close acForm, Me.Name

Exit_cmdOpenfrmDuctTakeoff_Click:
Exit Sub

Err_cmdOpenfrmDuctTakeoff_Click:
MsgBox Err.Description
Resume Exit_cmdOpenfrmDuctTakeoff_Click

End Sub

Thank you.
Kevin Sprinkel
 
K

Kevin Sprinkel

Solved this one. The JobNumber is actually a string, so
I needed "'" on both sides of the value.
 
Top