473,487 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Loopcode

11 New Member
Hello!

I am trying to get my Access closed after three failed password attempts. To do it, my ICT teacher told me that I have to find a loopcode. I tried to find it everywhere, but it is quite hard do to it. In this code I also need a counter that counts number of attempts. Any Ideas?

I only know a beginning:

Dim counter As Integer

Hope, you have an answer for my question! Thanks a lot!
Oct 24 '07 #1
15 1606
NeoPa
32,556 Recognized Expert Moderator MVP
Morfeus,

We are very careful here about doing school / university work for members as we really don't want to impeded the learning process. Having said that, we will try to assist in ways that help rather than doing it for you.
I will give you a basic example of loop code so that you have an understanding of what your teacher's talking about.
Remember though, your teachers are there to help and they can explain the concepts to you too if you find there's anything you are having trouble over.
Anyway, this is a simple loop :
Expand|Select|Wrap|Line Numbers
  1. Dim Counter As Integer
  2.  
  3. For Counter = 1 To 9
  4.   Call MsgBox("The variable Counter has now reached " & Counter)
  5. Next Counter
Oct 24 '07 #2
MorFeuS
11 New Member
Yeah, it is not really necessary to have that loopcode in my coursework, but my teacher said that if you'll find how to crack it, you will get more marks. He also said, that he won't help us, therefore I need to find full loopcode:< Can you help me?

Regards.
Oct 26 '07 #3
NeoPa
32,556 Recognized Expert Moderator MVP
In that case you don't really need to find full loop code, but rather you need to think about the loop code. You have an example of what happens in a loop and you know the actual problem you've been set.
First go through the very basic code in my post, then think about how you can use this concept in your own situation.
This site is really not about providing ready-made solutions. Nor would your best interests be served that way either.
Good luck - and remember we may still be able to help - but not simply by providing solutions.
Oct 26 '07 #4
MorFeuS
11 New Member
Heh, ok I will try to do that on my own, but I don't really expect that I will crack that code;) The only thing I can do in VB is simple password setup :P Thanks, anyway.
Oct 26 '07 #5
NeoPa
32,556 Recognized Expert Moderator MVP
MorFeuS, just because we can't do your swimming for you is no reason to assume you're going to drown. We can still help with ideas, just can't do it all for you.
What don't you get about looping code?
Oct 26 '07 #6
MorFeuS
11 New Member
Yeah, but still I don't know how to start ;)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command5_Click()
  2. If Text1 = "Milosz" And Text3 = "hello" Then
  3. DoCmd.Close
  4. DoCmd.OpenForm "Table form"
  5. Else: MsgBox "wrong password or username, please re-enter"
  6. End If
  7. End Sub
That is the first thing I did. So I know what is my password and username. After that I need to start with a loopcode, that would count number of attempts. The beginning is:
Expand|Select|Wrap|Line Numbers
  1. Dim counter As Integer
This is the place where I got stuck...

What I would do is to write:
Expand|Select|Wrap|Line Numbers
  1. If Text2 = "Hello" Then
  2. doCmd.close
  3. doCmd.openform "Table form"
  4. Else: msgBox "bla bla bla"
Here I would put a code that would take one attempt out of three attempts. After that I would use the same code (If text2. = etc. etc) two more times and after that I would:

1. use a code, that would close database... maybe Unload me ?

2. I would use commands:
Expand|Select|Wrap|Line Numbers
  1. doCmd.close
  2. doCmd.openform "Access Denied Form"
The second option is kinda lame, therefore i would use the first one... But I don't know tha code at all. You gave me some list with codes, but I don't know where to use them.

Ok, I tried to swimm, now tell me how to swimm :D

Regards.
Oct 28 '07 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Right then. Let's see if we can't manage a stroke or two here.
I must start by clarifying my understanding otherwise we'll only get confused.
I can see from your example code that you're using three text fields. I can guess that one is the account code (Name) and one the password. Why would you need three?
Also, you submit the attempt by clicking on CommandButton Command5.
It's possible to handle loop counting with a construct like this, but if you want to show looping code properly, the loop management needs to be outside of the task that is being looped. In pseudo-code that would be :
  1. Set up looping variable
  2. (A) Potentially check variable here
    {If loop finished then continue processing at (C)}
  3. Do task
  4. (B) Potentially check variable here
    {If loop not finished then continue processing at (A)}
  5. (C) Continue with code after loop
For your task that means that showing the form and hiding (closing) it should all be included within the loop.

Please answer my question above, and let me know how much sense you can make of what I've said so far.
Oct 28 '07 #8
MorFeuS
11 New Member
I have three... because I do. It's just happened that for first textbox I was given Text1, and second textbox was Text3 already. So, it is like it's jumped number 2, and gone straight to number 3.

Im not so skilled in english, though I think I understood what you mean. So the 'task' is the If statement (if text1 = "blba" And Text3 = "sdsa" Then). So the loopcode itself has to be after the task, with a new Sub ?

And the list you gave me now, means:

1. Here I set variables, for example how many attempts?
2. This code check if the password is correct or not.
3. If the password is alright it goes straight to C.
4. If the password is not correct it carries on the work
5. Checking the password.
6. If the password is not correct, goes back to point 2.

7. Code after a loop.

When I first read your post I thought I understood it vey well, however in the middle of typing my post, I got confused.

Regards.
Oct 28 '07 #9
NeoPa
32,556 Recognized Expert Moderator MVP
...
When I first read your post I thought I understood it vey well, however in the middle of typing my post, I got confused.
...
I get that all the time - Don't worry about it :D

I've changed post #8 to make it clearer hopefully :)
By the way, your post #7 refers to an item called Text2. That's why I was confused. You mean you have two TextBoxes called [Text1] & [Text3] yes?
Check through post #8 again and see if it makes more sense.
Checking the variable simply means checking the looping variable - not checking the password.
Checking the password, as well as showing and hiding the form, is all part of step 3 (Do Task).
Oct 29 '07 #10
MorFeuS
11 New Member
By the way, your post #7 refers to an item called Text2. That's why I was confused. You mean you have two TextBoxes called [Text1] & [Text3] yes?
Oh yes, I have only two textboxes, TextBox1 and TextBox 3.
Oct 29 '07 #11
NeoPa
32,556 Recognized Expert Moderator MVP
OK good.
Did you have a chance to review post #8 again? And does it make more sense now?
Oct 29 '07 #12
MorFeuS
11 New Member
Yes, it does. Thanks for helping me anyway. So, what do you want me to do now?:D
Oct 29 '07 #13
NeoPa
32,556 Recognized Expert Moderator MVP
I think another post like your #9 which lays out your current understanding.
Then you should look at step 3 more closely. Say what steps that would be broken down into.
I will look at both of these replies (when they come) and tell you if you're thinking along the right lines. If so, we have the concept part sorted which is good. The rest is simply coding it into Access VBA in your database.
Oct 29 '07 #14
MorFeuS
11 New Member
Thanks for helping, however I found out other loopcode. I found it on other page, because I didn't know how to do yours. HOWEVER the code didn't work, so I had to change it, modify it a little bit:P So your lessons weren't waste, they helped me a lot.

However I face other problems now. One of them is that I can still CLOSE (by clicking the cross) my LOGIN PAGE without entering password and username and process to full database. How to lock/disable that cross?

EDIT:

NVM I found the solution :P
Oct 31 '07 #15
NeoPa
32,556 Recognized Expert Moderator MVP
No problem. I'm glad you found your way.
BTW You would use the Form_Unload(Cancel) procedure and set Cancel to true unless you have closed it the way you want to allow.
Oct 31 '07 #16

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.