Passing a combo box value to an update query

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

S

Dear All,

To enter the data relevant to a particular product in my database, I
have created a data entry form that is composed by two different
parts: a combo box where I have the "product name" and a subform
having "data sheet" format where I want to insert the data.
The subform is populated according to the values of two other tables
(XX and YY).
The value in the combo box is the primary key of one of the tables
feeding the subform.

When I try to enter the data for a new record I get this message:

"Index or primary key cannot contain a Null value"

which makes sense, since the combo box is independent from the sub
form.

To solve this problem I have to find a way to state that, if the user
enters data in the subform, the field "product name" of the table XX
is to be set as the form combo box value.

Is there anyone who faced this problem before and can maybe give me
help?

Thanks very much in advance,

David
 
Place a textbox on the subform (hidden if you wish) and set its default
value to

=Me.Parent.cboMyCombobox

This will place the value of the combo box in the textbox whenever you
create a new record. Bind this textbox to the associated field in the
subform's data source.
 
Hello Wayne,

Thanks very much for your precious tip: I do not get anymore the error
message and I am able to insert the data properly but I have to say
that, in my version of Access (1997), this works better:

=[Me].[Parent].[cboMyCombobox]

In the text box "tbxProdName" that I have added, I set the property
"Visible" = No.
Still, when I open the subform in data sheet format, the column
tbxProdName is there. Is there anything else you recommend to hide it?

Thanks very much again,

David
 
You're right, after you type it Access will put the brackets in. It does it
in the newer versions also. In the datasheet view, you can hide the field by
dragging it closed (like an Excel column). I don't know of any way to
prevent the user from reopening it, you may want to set the textbox to
Locked as well so that it can't be changed by the user.

--
Wayne Morgan


S said:
Hello Wayne,

Thanks very much for your precious tip: I do not get anymore the error
message and I am able to insert the data properly but I have to say
that, in my version of Access (1997), this works better:

=[Me].[Parent].[cboMyCombobox]

In the text box "tbxProdName" that I have added, I set the property
"Visible" = No.
Still, when I open the subform in data sheet format, the column
tbxProdName is there. Is there anything else you recommend to hide it?

Thanks very much again,

David

"Wayne Morgan" <[email protected]> wrote in
message news: said:
Place a textbox on the subform (hidden if you wish) and set its default
value to

=Me.Parent.cboMyCombobox

This will place the value of the combo box in the textbox whenever you
create a new record. Bind this textbox to the associated field in the
subform's data source.
 
Back
Top