Forms Will Not Interact?

  • Thread starter Thread starter Steven V. Olson
  • Start date Start date
S

Steven V. Olson

I am having trouble with the following code for Office
2000 vba. I am attempting to open a form which contains
control buttons that input text into a text box on a
different form.

First, I open a form named "Select Lens Or Segment Styles
Form", which contains the selection buttons. The following
subroutine accomplishes this task nicely:

Private Sub Command165_Click()
On Error GoTo Err_Command165_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Select Lens Or Segment Styles Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command165_Click:
Exit Sub

Err_Command165_Click:
MsgBox Err.Description
Resume Exit_Command165_Click

End Sub

'This subroutine opens a form named "Select Lens Or
Segment Styles Form"


Next, I click on a command button on this form. The
command button closes the the form named "Select Lens Or
Segment Styles Form", which it performs correctly.

However, the next commands are not executing. I am asking
that the words "S.V. Polycarb." be entered into a text box
named LensOrSegmentStyles which is on the previously
active form named "Patient Safety Rx Order Form" Finally,
the last command askes that the form data be refreshed.
See the code below:



Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

DoCmd.Close

'This command closes the form named "Select Lens Or
Segment Styles Form"

LensOrSegmentStyles = "S.V. Polycarb."

' This command types the text "S.V. Polycarb." Into
the text box named LensOrSegmentStyles.

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, ,
acMenuVer70

' This command refreshes the screen

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub


No errors occur when the command buttons are pressed,
however, no words appear in the text box either. Can
someone help me correct this code so that it functions
properly? Please e-mail responses to (e-mail address removed).

Sincerely,

Steven V. Olson, (e-mail address removed)
 
Steven,

Instead of this line...

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, ,
acMenuVer70

try..

[Forms]![Patient Safety Rx Order Form]![LensOrSegmentStyles] = "S.V.
Polycarb."

However I don't think this is what you really want. My guess is that you
want to pull the selection off of the styles form and then pass it on to the
order form. In your code as is you coulldn't do this as you are closing the
form as the first line of code.

You didn't say what the name of the selection control is on the styles form
(Me, below) so I will use the one from the order form...


[Forms]![Patient Safety Rx Order Form]![LensOrSegmentStyles] =
Me![LensOrSegmentStyles]
DoCmd.Close

Also, you will save yourself a lot of headaches if you take the spaces out
of your forms and control names.

Gary Miller
 
Back
Top