Error running a line of code (another one)

S

skulmat

I am having another problem with this line of code:

DoCmd.OpenForm "Orders", acNormal, , "OrderNumber = " &
me.OrderNumber, acFormEdit

it is not pulling in any info from the combo box inorder to open the right
entry in the order form, it pops up a value box for me to fill out. Also when
i then do manually enter a OrderNumber, it takes me to the debugger saying
"runtime error 2501" "the open form actiion was
canceled

thank you
 
K

Ken Snell [MVP]

Then it's telling you that the "Orders" form's RecordSource query does not
contain a field named OrderNumber.
 
S

skulmat

You are right, I forgot to add that field to the query, i only had enterd it
to the table. So now it doesnt pop up asking me for the data, but i still get
the "error 2501 the open form actiion was canceled"
 
K

Ken Snell [MVP]

Is OrderNumber a text field? If yes, delimit the value from the textbox with
' characters:

DoCmd.OpenForm "Orders", acNormal, , "OrderNumber = '" & me.OrderNumber &
"'", acFormEdit
 
D

Dirk Goldgar

skulmat said:
I am having another problem with this line of code:

DoCmd.OpenForm "Orders", acNormal, , "OrderNumber = " &
me.OrderNumber, acFormEdit

it is not pulling in any info from the combo box inorder to open the
right entry in the order form, it pops up a value box for me to fill
out. Also when i then do manually enter a OrderNumber, it takes me to
the debugger saying "runtime error 2501" "the open form actiion was
canceled

thank you

Does the recordsource of the form "Orders" have a field named
"OrderNumber"?

Does the form on which you are running this line of code have a control
or field named "OrderNumber"?

Is OrderNumber a number or autonumber field, or is it text?
 
S

skulmat

well now it doesnt give me any error, but it just opens it up at a blank
record, it does not take me to the record that i chose in the "ordernumber"
combobox

thankx again
 
S

skulmat

yes, yes, and it a text box.

thank you

Dirk Goldgar said:
Does the recordsource of the form "Orders" have a field named
"OrderNumber"?

Does the form on which you are running this line of code have a control
or field named "OrderNumber"?

Is OrderNumber a number or autonumber field, or is it text?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
K

Ken Snell [MVP]

Are you sure that your form that is running this code has a value for the
OrderNumber field/control?
 
S

skulmat

I just double checked. I have a combobox thats name is OrderNumber .
this combobox gets its scource from the table Orders field OrderNumber .
thank you
 
D

Dirk Goldgar

skulmat said:
yes, yes, and it a text box.

thank you

Not a "text box", that's a type of control. What I'm asking about is
the type of *field* (in the table). Howver, from your responses to Ken
Snell, it sounds like OrderNumber is a text field. Following up on your
reply to Ken, the question is whether the combo box "OrderNumber"
actually has any value. If that control is Null, you won't find any
matching records. When you run this code, does the OrderNumber combo
box show a value?
 
S

skulmat

You were right, i had only set the scource of teh combobox to be that
information, so now i set the "control scource" to be =
[Orders]![OrderNumber] , but now it does not let me select anything, saying
that the record is bound to ....

thank you
 
D

Dirk Goldgar

skulmat said:
You were right, i had only set the scource of teh combobox to be that
information, so now i set the "control scource" to be =
[Orders]![OrderNumber] , but now it does not let me select anything,
saying that the record is bound to ....

It would have been better to post the entire error message. I think,
though, that there's something screwy about how you have this set up.
What is the name of the form that contains this code? What is the
recordsource of that form? What, in plain words, are you actually
trying to do? Give us a bigger picture.
 
S

skulmat

I am trying to create a form that will give you two choices
choice A will be to create a new order, so i have this code
DoCmd.OpenForm "Orders", acNormal, , , acFormAdd

Choise B will be to edit an existing Order so i created a combo box that get
it record

scource from table that stores the Orders and it should use the OrderName
field.
then i created a command button with this code
DoCmd.OpenForm "Orders", acNormal, , "OrderNumber = '" & Me.OrderNumber &
"'", acFormEdit

so hopefully if you choose the OrderName from the combo box and then click
the button, it

will open up only that record in the Orders form in edit mode.

My database is a modified northwind database, so the default form/table
names are the same

except for what i added. I added in the "ordername" field.

The error is "the control can not be edited as it is bound to
'orders!ordernumber'
thankyou

Dirk Goldgar said:
skulmat said:
You were right, i had only set the scource of teh combobox to be that
information, so now i set the "control scource" to be =
[Orders]![OrderNumber] , but now it does not let me select anything,
saying that the record is bound to ....

It would have been better to post the entire error message. I think,
though, that there's something screwy about how you have this set up.
What is the name of the form that contains this code? What is the
recordsource of that form? What, in plain words, are you actually
trying to do? Give us a bigger picture.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

skulmat said:
I am trying to create a form that will give you two choices
choice A will be to create a new order, so i have this code
DoCmd.OpenForm "Orders", acNormal, , , acFormAdd

Choise B will be to edit an existing Order so i created a combo box
that get it record

scource from table that stores the Orders and it should use the
OrderName field.
then i created a command button with this code
DoCmd.OpenForm "Orders", acNormal, , "OrderNumber = '" &
Me.OrderNumber & "'", acFormEdit

so hopefully if you choose the OrderName from the combo box and then
click the button, it

will open up only that record in the Orders form in edit mode.

My database is a modified northwind database, so the default
form/table names are the same

except for what i added. I added in the "ordername" field.

The error is "the control can not be edited as it is bound to
'orders!ordernumber'
thankyou

You didn't really answer my questions about the name and recorsource of
the form that contains this combo box and the buttons. However, I'm
going to assume for the moment that the form is unbound -- that is, that
it has no recordsource -- and that you haven't made the mistake of
putting these controls on the Orders form itself.

For the sort of thing you are doing the combo box should *not* be
bound -- it should have no controlsource. But you may have made an
error in setting up the combo box. Where did you add this field
"OrderName"? You told us that the combo box is named "OrderNumber", so
this is the first we've heard of anything called "OrderName".

Please post the following properties of the combo box:

Name
RowSource
ControlSource
BoundColumn
ColumnCount
ColumnWidths

That ought to be enough to figure out what's going on.
 
S

skulmat

Sorry, I mistyped about OrderName, I meant to write OrderNumber. It is a
seperate Form, and i started the form from a blank form, so there is no
control scource for the form.

Also, I tried it with the combobox bound and unbound, when it is bound it
doesnt let me select anything from the list, so now that i unbound it here is
the settings.

Name = OrderNumber
RowSource = SELECT Orders.OrderID, Orders.OrderNumber FROM Orders;
ControlSource= {blank}
BoundColumn = 1
ColumnCount = 2
ColumnWidths= 0";1"

When the settings are like this and i click on the command button it opens
up the form but it does not take me to the proper record, all it shows is a
blank record, but on the bottom it says filterd.

thank you
 
D

Dirk Goldgar

skulmat said:
Sorry, I mistyped about OrderName, I meant to write OrderNumber. It
is a seperate Form, and i started the form from a blank form, so
there is no control scource for the form.

Also, I tried it with the combobox bound and unbound, when it is
bound it doesnt let me select anything from the list, so now that i
unbound it here is the settings.

Name = OrderNumber
RowSource = SELECT Orders.OrderID, Orders.OrderNumber FROM Orders;
ControlSource= {blank}
BoundColumn = 1
ColumnCount = 2
ColumnWidths= 0";1"

When the settings are like this and i click on the command button it
opens up the form but it does not take me to the proper record, all
it shows is a blank record, but on the bottom it says filterd.

thank you

Apparently your Orders table has two fields, OrderID and OrderNumber.
Are they both unique keys to the table? Your combo box's bound column
is OrderID, though it only displays OrderNumber. That means that the
value of the combo box, event though it calls itself "OrderNumber", is
really OrderID. So -- assuming OrderID is a unique key to the table and
is a numeric field -- your code to open the Orders form should be:

DoCmd.OpenForm "Orders", acNormal, , _
"OrderID = " & Me!OrderNumber, _
acFormEdit

Or, if you want to use the OrderNumber field to select on, you could say

DoCmd.OpenForm "Orders", acNormal, , _
"OrderNumber = '" & Me!OrderNumber.Column(1) & "'", _
acFormEdit
 

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

Top