Displaying the value of a variable on a form (1 Viewer)

duke217

Registered User.
Local time
Today, 23:58
Joined
Jan 23, 2018
Messages
17
Hi all,

I would like to display the status of the network connection on a form.

Here is what I have done so far:

1. I put this code in the (General) section of my form:

Code:
Private Sub Connection_Status()
Dim Network_Cnx As String

If My.Computer.Network.IsAvailable Then
    Network_Cnx = "UP"
Else
    Network_Cnx = "DOWN"
End If

End Sub

Then, i created a text box (TextNetwSTS) where I would like the status displayed (UP or DOWN) and in it code, I put:

Code:
Private Sub TextNetwSTS_BeforeUpdate(Cancel As Integer)
TexNetwSTS.Value = Network_Cnx.Value
End Sub

Disappointing result: the text box remains blank.

Any idea what I did wrong?

Thanks a lot!
 

Minty

AWF VIP
Local time
Today, 22:58
Joined
Jul 26, 2013
Messages
10,371
I am pretty sure that

Code:
My.Computer.Network.IsAvailable

Is not understood by Access - where did you find this ?
 

plog

Banishment Pending
Local time
Today, 16:58
Joined
May 11, 2011
Messages
11,643
1 word: Scope.

Variables are not eternal and ephermal, they exist within certain parameters. While both your functions have variables called 'Network_Cnx', they are 2 different variables and cease to exist once a function/sub hits its End statement.

ConnectionStatus assigns a value to Network_Cnx, but does nothing with it.
TextNetwSTS_BeforeUpdate uses Network_Cnx, but never assigns it a value.

You need to bridge the gap. Either move the code from ConnectionStatus into TextNetwSTS_BeforeUpdate. Or make ConnectionStatus a function which returns a value and call it from TextNetwSTS_BeforeUpdate.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:58
Joined
May 7, 2009
Messages
19,230
you should call Connection_Status first before you assign the value:

Private Sub TextNetwSTS_BeforeUpdate(Cancel As Integer)
Call Connection_Status
TexNetwSTS.Value = Network_Cnx.Value
End Sub
 

Users who are viewing this thread

Top Bottom