PC Review


Reply
Thread Tools Rate Thread

Command button - compare computer name with a pass code

 
 
Roger on Excel
Guest
Posts: n/a
 
      4th Dec 2009
[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

 
Reply With Quote
 
 
 
 
AB
Guest
Posts: n/a
 
      4th Dec 2009
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
<RogeronEx...@discussions.microsoft.com> 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


 
Reply With Quote
 
Roger on Excel
Guest
Posts: n/a
 
      4th Dec 2009
Dear AB,

Many thanks for this eloquent solution - works very very nicely

Have a great weekend

Best regards,

Roger



"AB" wrote:

> 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
> <RogeronEx...@discussions.microsoft.com> 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

>
> .
>

 
Reply With Quote
 
AB
Guest
Posts: n/a
 
      4th Dec 2009
Thanks for the feedback!

Have a great weekend you too!

A.

On 4 Dec, 13:00, Roger on Excel
<RogeronEx...@discussions.microsoft.com> wrote:
> Dear AB,
>
> Many thanks for this eloquent solution - works very very nicely
>
> Have a great weekend
>
> Best regards,
>
> Roger
>
>
>
> "AB" wrote:
> > 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
> > <RogeronEx...@discussions.microsoft.com> 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 buttondoesnt
> > > open the second userform

>
> > > Can anyone help?

>
> > > Thanks,

>
> > > Roger

>
> > .- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Command Button info =?Utf-8?B?SiBTdHJlZ2Vy?= Microsoft Excel Programming 3 5th Feb 2010 08:51 PM
Pass Defined Name to a Command Button Connie Microsoft Excel Programming 3 10th Oct 2006 07:45 AM
Pass a cell in sheet to macro or command button Connie Microsoft Excel Programming 2 8th Oct 2006 04:54 PM
Pass variable to command button on click event on form =?Utf-8?B?SlJfMDYwNjIwMDU=?= Microsoft Access VBA Modules 1 7th Feb 2006 10:19 PM
THIRD REQUEST-Coding a Command Button to Pass Value boconnor Microsoft Access Form Coding 0 25th Aug 2003 02:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.