Command button - compare computer name with a pass code

R

Roger on Excel

[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
 
A

AB

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.
 
R

Roger on Excel

Dear AB,

Many thanks for this eloquent solution - works very very nicely

Have a great weekend

Best regards,

Roger



AB said:
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.


[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

.
 
A

AB

Thanks for the feedback!

Have a great weekend you too!

A.

Dear AB,

Many thanks for this eloquent solution - works very very nicely

Have a great weekend

Best regards,

Roger



AB said:
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
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.
[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 buttondoesnt
open the second userform
Can anyone help?
Thanks,
Roger
.- Hide quoted text -

- Show quoted text -
 

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