Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Command button - compare computer name with a pass code

[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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Command button - compare computer name with a pass code

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


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Command button - compare computer name with a pass code

Thanks for the feedback!

Have a great weekend you too!

A.

On 4 Dec, 13:00, Roger on Excel
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
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


.- Hide quoted text -


- Show quoted text -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Command Button info J Streger Excel Programming 3 February 5th 10 08:51 PM
Pass Defined Name to a Command Button Connie Excel Programming 3 October 10th 06 07:45 AM
Pass a cell in sheet to macro or command button Connie Excel Programming 2 October 8th 06 04:54 PM
Command button code taps54 Excel Programming 3 September 21st 06 01:16 PM
VBA code behind command button [email protected] Excel Worksheet Functions 1 March 22nd 06 08:13 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"