Why Doesn't this work?

H

Hank

I have several forms open and have a click event on one form. It should
populate a field with a number but doesn't. I am lost !!! Code Follows:

Private Sub CustOrderNum_Click()
Me.CustOrderNum.Value = Forms![AirWayBill]![AirWayBillNo]
DoCmd.Close acForm, Me.Name, acSaveYes
End Sub

Please help me AGAIN!!!!!
 
P

Paul Shapiro

It's probably doing what you told it. As soon as it assigns the customer
order number, you told it to close the form and save any changes TO THE
FORM, not the data. So you'll never see the customer number assignment on
the form. Maybe you mean to save the edited row, rather than close the form?
That could be done as:
Me.Dirty = false

You could also use the debugger to verify that your expression
Forms![AirWayBill]![AirWayBillNo] is returning the value you expect. I would
usually use Forms![AirWayBill].Form![AirWayBillNo] (note the .Form inserted
in the middle).

This will generate an error if the AirWayBill form isn't open. It might be
good to check for that first, but I don't think that's the current issue.
 
D

Douglas J. Steele

Since Value is the default property for a text box, it'll make no difference
whether or not the property name is there.

I agree that there's no need to save the form (as Paul already pointed out),
but removing that line isn't going to ensure that the data is saved.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Steve said:
Remove "Value" in the second line and remove "Me.Name, acSaveYes" in the
third line and it should then work.

Steve
(e-mail address removed)


Hank said:
I have several forms open and have a click event on one form. It should
populate a field with a number but doesn't. I am lost !!! Code Follows:

Private Sub CustOrderNum_Click()
Me.CustOrderNum.Value = Forms![AirWayBill]![AirWayBillNo]
DoCmd.Close acForm, Me.Name, acSaveYes
End Sub

Please help me AGAIN!!!!!
 
D

Dirk Goldgar

Steve said:
Remove "Value" in the second line

Why on Earth should he do that? If CustOrderNum is a control that can have
a Value property, then assigning to Me.CustOrderNum is the same as assigning
to Me.CustOrderNum.Value -- because Value will be the default property of
such a control.
and remove "Me.Name, acSaveYes" in the third line and it should then work.

The only effect removing that should have would be stopping the undesired
saving of the form design, but I don't believe it will have any effect on
the value of CustOrderNum.
 
D

Dirk Goldgar

Hank said:
I have several forms open and have a click event on one form. It should
populate a field with a number but doesn't. I am lost !!! Code Follows:

Private Sub CustOrderNum_Click()
Me.CustOrderNum.Value = Forms![AirWayBill]![AirWayBillNo]
DoCmd.Close acForm, Me.Name, acSaveYes
End Sub


Are any error messages displayed?

Are you clicking on CustOrderNum? This code will do nothing unless you do.

Is the form "AirWayBill" open when you click on CustOrderNum? If it isn't,
I'd expect an error to be raised.

Does the control AirWayBillNo on form AirwayBill contain a value at the
moment when you click on CustOrderNum (on the current form)? If not, you'll
just be assigning Null to CustOrderNum.

Since your code closes the form immediately after the value is assigned to
CustOrderNum, how do you know it isn't working? You might try temporarily
commenting out the "DoCmd.Close" line, just to see what happens when you
click CustOrderNum.

As Paul Shapiro has pointed out, you probably don't want to be specifying
acSaveYes when you close the form, because that saves changes to the
*design* of the form. However, just closing the form if its record has been
modified should force the record to be saved, unless there is some reason
why it can't be.

If CustOrderNum *is* being assigned a number, but it isn't being saved when
you close the form, I wonder if perhaps that control is not bound to a
field. What is the ControlSource of CustOrderNum?
 

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