Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default question for Tom Ogilvi

Hi Tom,
You gave me the following code to test for a name and a code before entering
the application
This works fine for me !
However, if the code is filled in wrong i would like the user to have 2 more
tries in the code field before closing down the application.
can you help me once more?
thanks,


Private Sub OK_Click()
Dim nmeLst As Range, codeLst As Range
Dim resName As Variant, resCode As Variant
If txt_naam = "" And txt_code = "" Then
MsgBox "Please enter name and code"
txt_naam.SetFocus
Exit Sub
End If
If txt_naam = "" Then
MsgBox "Please enter name"
txt_naam.SetFocus
Exit Sub
End If
If txt_code = "" Then
MsgBox "Please enter code"
txt_code.SetFocus
Exit Sub
End If
With Worksheets("Check")
Set codeLst = .Range(.Cells(1, "H"), .Cells(1, "H").End(xlDown))
' Set nameLst = .Range(.Cells(1, "G"), .Cells(1, "G").End(xlDown))
End With
'resName = Application.Match(txt_naam, nmeLst, 0)
resCode = Application.Match(txt_code, codeLst, 0)
If Not IsError(resCode) Then
ActiveSheet.Range("A1").Value = txt_naam
Else
Unload Me
ThisWorkbook.Close Savechanges:=False
End If
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default question for Tom Ogilvi

Private Sub OK_Click()
Dim nmeLst As Range, codeLst As Range
Dim resName As Variant, resCode As Variant
Static Counter As Long
If txt_naam = "" And txt_code = "" Then
MsgBox "Please enter name and code"
txt_naam.SetFocus
Exit Sub
End If
If txt_naam = "" Then
MsgBox "Please enter name"
txt_naam.SetFocus
Exit Sub
End If
If txt_code = "" Then
MsgBox "Please enter code"
txt_code.SetFocus
Exit Sub
End If
With Worksheets("Check")
Set codeLst = .Range(.Cells(1, "H"), .Cells(1, "H").End(xlDown))
' Set nameLst = .Range(.Cells(1, "G"), .Cells(1, "G").End(xlDown))
End With
'resName = Application.Match(txt_naam, nmeLst, 0)
resCode = Application.Match(txt_code, codeLst, 0)
If Not IsError(resCode) Then
ActiveSheet.Range("A1").Value = txt_naam
ElseIf Counter = 3 Then
Unload Me
ThisWorkbook.Close Savechanges:=False
Else
Counter = Counter + 1
MsgBox "Please enter code", , "Try Again"
End If
End Sub


"Pierre via OfficeKB.com" wrote:

Hi Tom,
You gave me the following code to test for a name and a code before entering
the application
This works fine for me !
However, if the code is filled in wrong i would like the user to have 2 more
tries in the code field before closing down the application.
can you help me once more?
thanks,


Private Sub OK_Click()
Dim nmeLst As Range, codeLst As Range
Dim resName As Variant, resCode As Variant
If txt_naam = "" And txt_code = "" Then
MsgBox "Please enter name and code"
txt_naam.SetFocus
Exit Sub
End If
If txt_naam = "" Then
MsgBox "Please enter name"
txt_naam.SetFocus
Exit Sub
End If
If txt_code = "" Then
MsgBox "Please enter code"
txt_code.SetFocus
Exit Sub
End If
With Worksheets("Check")
Set codeLst = .Range(.Cells(1, "H"), .Cells(1, "H").End(xlDown))
' Set nameLst = .Range(.Cells(1, "G"), .Cells(1, "G").End(xlDown))
End With
'resName = Application.Match(txt_naam, nmeLst, 0)
resCode = Application.Match(txt_code, codeLst, 0)
If Not IsError(resCode) Then
ActiveSheet.Range("A1").Value = txt_naam
Else
Unload Me
ThisWorkbook.Close Savechanges:=False
End If
End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default question for Tom Ogilvi

Thanks Patrick !!
This works fine for me !
Pierre


Patrick Molloy wrote:
Private Sub OK_Click()
Dim nmeLst As Range, codeLst As Range
Dim resName As Variant, resCode As Variant
Static Counter As Long
If txt_naam = "" And txt_code = "" Then
MsgBox "Please enter name and code"
txt_naam.SetFocus
Exit Sub
End If
If txt_naam = "" Then
MsgBox "Please enter name"
txt_naam.SetFocus
Exit Sub
End If
If txt_code = "" Then
MsgBox "Please enter code"
txt_code.SetFocus
Exit Sub
End If
With Worksheets("Check")
Set codeLst = .Range(.Cells(1, "H"), .Cells(1, "H").End(xlDown))
' Set nameLst = .Range(.Cells(1, "G"), .Cells(1, "G").End(xlDown))
End With
'resName = Application.Match(txt_naam, nmeLst, 0)
resCode = Application.Match(txt_code, codeLst, 0)
If Not IsError(resCode) Then
ActiveSheet.Range("A1").Value = txt_naam
ElseIf Counter = 3 Then
Unload Me
ThisWorkbook.Close Savechanges:=False
Else
Counter = Counter + 1
MsgBox "Please enter code", , "Try Again"
End If
End Sub

Hi Tom,
You gave me the following code to test for a name and a code before entering

[quoted text clipped - 36 lines]
End If
End Sub


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200511/1
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
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 05:57 AM.

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

About Us

"It's about Microsoft Excel"