Why Won't my Event Code Work?

S

Steven V. Olson

The following code is used in a click event for a command
button located on a form called "Clear Lens Or Segment
Styles Form". This form is linked to another form
called "Patient Safety Rx Order Form" by the common
field "Rx#". Both Forms utilize the same table Rx Orders
Table. As I share the code I will explain how it
functions, what works and what doesn't work. The code is
as follows:

Private Sub Command45_Click()
On Error GoTo Err_Command45_Click

LensOrSegmentStyles = "S.V. Clear Glass."

'This code enters the value into a text box on the
Patient Safety Rx Order Form, and it is working fine.

Tint = "Clear."

'This code enters the value into another text box on
the Patient Safety Rx Order Form, and it is working fine.

Material = 2

'This code enters a value into an option box field on
the Patient Safety Rx Order Form, and it is working fine.

HardeningProcess = 1

'This code should enter a different value into
another Option box field on the Patient Safety Rx Order
Form, however this value does not get entered. When I
place another command button directly on the "Patient
Safety Rx Order Form" The code " Hardening Process = 1 "
works just fine. I don't understand why the code works for
the Material = 2 entry, but it won't work for the
HardeningProcess = 1 entry. What gives?

DoCmd.Close

'This command closes the Clear Lens Or Segment Styles
Form, and it works just fine.

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, ,
acMenuVer70

'This command refreshes the screen and it is working
fine.

Exit_Command45_Click:
Exit Sub

Err_Command45_Click:
MsgBox Err.Description
Resume Exit_Command45_Click

End Sub

Please send replies to (e-mail address removed)

Sincerely,

Steve Olson
 
K

Ken Snell

It's not clear from your code how it knows which form is to be the source of
these controls....how do you "establish" this?

Is it possible that you have a control on the "Clear Lens Or Segment Styles
Form" with the name of HardeningProcess?

You need to give us a bit more info.

Also, just a word of advice....whenever you use the DoCmd.Close action, it's
best to always specify what type of object is to be closed and to specify
the name of the object to be closed. Otherwise, your code will close
whatever has the focus at the time the DoCmd.Close action runs. Sometimes,
it's not what you expect.

DoCmd.Close acForm, "FormName"
 

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