We help IT Professionals succeed at work.

Write data between screens using VBA

BryanKipp
BryanKipp used Ask the Experts™
on
I have a non-office application that uses VBA6.5. I have two screens and have a need to be able to write a value or call a procedure on the other screen. There is no way to set up global objects.

There is some sample code as follows:
 On Screen 1

 
'This can be tested in RSView Studio by test running both displays.
Public sName As String

Sub ShowMsgbox(sMessage As String)
    'This routine takes a string parameter
    'Always use error handling during runtime
    
    On Error GoTo ErrHandler
    
    MsgBox sMessage
    Exit Sub
    
ErrHandler:
    LogMessage Err.Description, cliActivitySeverityError
End Sub

Private Sub Button3_Released()

End Sub

Private Sub Display_AnimationStart()
    'Always use error handling during runtime
    
    On Error GoTo ErrHandler

    sName = Me.FullName
    Exit Sub
    
ErrHandler:
    LogMessage Err.Description, cliActivitySeverityError
End Sub

Open in new window


On Screen 2

 
Private Sub btnVBACode_Released()
    'Always use error handling during runtime
    On Error GoTo ErrHandler
    
    'declare the dislays collection
    Dim ds As Displays
    
    'assign the variable to the loadedDisplays object
    Set ds = LoadedDisplays
    'run the procecure ShowMsgbox that is on the Main VBA Code graphic
    ds.Item("Main VBA Code").ShowMsgbox "Running a procedure on another display from " & Me.Name
    Exit Sub
    
ErrHandler:
    LogMessage Err.Description, cliActivitySeverityError
End Sub
Private Sub btnVBAVariable_Released()
    'Always use error handling during runtime
    On Error GoTo ErrHandler
    
    'declare the dislays collection
    Dim ds As Displays
    Dim sOtherDisplayName As String
    
    'assign the variable to the loadedDisplays object
    Set ds = LoadedDisplays
    'read the variable sname that is on the Main VBA Code graphic
    sOtherDisplayName = ds.Item("Main VBA Code").sname
    txtVBAVariable.Caption = "Reading a VBA variable from " & sOtherDisplayName _
    & vbCrLf & "in " & Me.FullName & " at " & Now
    Exit Sub
    
ErrHandler:
    LogMessage Err.Description, cliActivitySeverityError
End Sub


Private Sub Display_AnimationStart()

End Sub

Open in new window


I have test run this and it does function, however what I need to be able to do is pass a parameter to a combobox on screen one via a button click on screen 2. I have tried modifying the sample code, but am missing something to make it work.

Any assistance would be greatly appreciated!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Brook BraswellApplication Development Manager

Commented:
Have you tried Screen2.ComboBox.Text = "What Ever" ?
Application Development Manager
Commented:
or rather, noting that you want a button from 2 to interact with a combo box on 1

' from screen 2

Private sub cmdButton_Click()
   Screen1.cboCombo.Text = "data"

End Sub
Top Expert 2014

Commented:
If your values are shown in controls, then you should be able to access the controls from a different application/form.  You will need to qualify the name of the control with the (other) form name.

If the values aren't shown on controls, you can create Public variable declarations in the General Declarations sections of the forms.  These Public variables act as (extended) form properties.

Author

Commented:
Thanks for this assistance! I thought I had tried that with no luck, but it functions beautifully.