What am I doing wrong? Parameter Query

  • Thread starter Thread starter Spidey3721
  • Start date Start date
S

Spidey3721

I have two forms: [ProjCostsFrm] and [NewCostFrm]

The [NewCostFrm] is a data entry form used to add new costs, which will show
up in the [ProjCostsFrm]

I want the default value of a bound (ProjectID) textbox, [ProjIDTxt] to
match the bound [ProjIDTxt] control on the [ProjCostsFrm]


For the [ProjIDTxt] Control Source, I have: [Forms]![ProjCostsFrm]![Project
ID]

It will not work.
 
Spidey3721 said:
I have two forms: [ProjCostsFrm] and [NewCostFrm]

The [NewCostFrm] is a data entry form used to add new costs, which
will show up in the [ProjCostsFrm]

I want the default value of a bound (ProjectID) textbox, [ProjIDTxt]
to match the bound [ProjIDTxt] control on the [ProjCostsFrm]


For the [ProjIDTxt] Control Source, I have:
[Forms]![ProjCostsFrm]![Project ID]

It will not work.

You're right, that won't work. <g> If you want the default value of a
text box to be something, it's the Default Value property you must set,
not the Control Source. Besides, you want [ProjIDTxt] on [NewCostFrm]
to be bound to the ProjectID field, right? So its Control Source must
be ProjectID.

If you're opening [NewCostFrm] from [ProjCostsFrm], so [ProjCostsFrm] is
always open with the desired value in its own [ProjIDTxt] control, then
you can set the Default Value property of [ProjIDTxt] on [NewCostFrm] to
this:

=[Forms]![ProjCostsFrm]![ProjIDTxt]

It's not completely clear to me whether [ProjIDTxt] is really the name
of the control on [ProjCostsFrm], because you also referred to [Project
ID]. So you may have to correct that.
 
I have two forms: [ProjCostsFrm] and [NewCostFrm]

The [NewCostFrm] is a data entry form used to add new costs, which will show
up in the [ProjCostsFrm]

I want the default value of a bound (ProjectID) textbox, [ProjIDTxt] to
match the bound [ProjIDTxt] control on the [ProjCostsFrm]


For the [ProjIDTxt] Control Source, I have: [Forms]![ProjCostsFrm]![Project
ID]

It will not work.

The ProjIDTxt textbox can be bound to a table field, *or* it can be
bound to an expression - but it can't be both!

I'd suggest using some VBA code in NewCostFrm's BeforeInsert event:

Private Sub Form_BeforeInsert(Cancel as Integer)
On Error GoTo Proc_Error
Me!ProjIDTxt = Forms![ProjCostsFrm]![Project ID]
Proc_Exit:
Exit Sub
Proc_Error:
If Err.Number = <whatever> Then
Resume Next
Else
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Resume Proc_Exit
End If
End Sub

Fill in "whatever" with the error number that you get when you try to
insert a record on NewCostFrm when ProjCostsFrm is not open.
 
Back
Top