View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
AB[_2_] AB[_2_] is offline
external usenet poster
 
Posts: 236
Default Command button - compare computer name with a pass code

Hi there,

The principle is exactly the same as in your other post. Something
along these lines:

Function MayProceed() As Boolean

Const ExpectedCompName As String = "TheCompName"

If StrComp(ExpectedCompName, Environ("Computername"),
vbTextCompare) = 0 Then
MayProceed = True
Else
MayProceed = False
End If

End Function

Private Sub CommandButton1_Click()

If MayProceed Then
Userform2.Show
Else
MsgBox "This solution was built for a computer with another
name!", vbExclamation
End If

End Sub

You'll notice that i ignored the listbox alltogether as there is the
Environ function that pulls the computer name on the fly. Obviously if
it's not what you want, then you can replace it with the refference to
the listbox.value as per your other post.
If you have to go with the listbox option then you need to make sure
that a 'row' in the list box has been selected (that's the reason why
i put the .listindex=-1 chekc in there) - somthing like
listbox.listindex=0.


On Dec 4, 3:10*am, Roger on Excel
wrote:
[Excel 2003]

I have a listbox on a userform which displays the computers name :

YOUR-X9X9X9X9

Is there a way to have a command button check this code against a string
within the command button code which will do the following

1) if the code matches, a second userform :Userform2 is shown
2) if the code doesnt match a warning is shown and the command button doesnt
open the second userform

Can anyone help?

Thanks,

Roger