Results 1 to 6 of 6
  1. #1
    tariq nawaz is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    31

    how to implement not to go to next firld on form after the first one filled



    input_Winwick_form1.zipinput_Winwick_form1.zip
    i am novice user to databases and VBA.
    i have developed a small application.
    i am stuck on a form called input.
    i have done some coding and conditions which are doing what i need to do.
    i am stuck that i dont want to move to next field on Form until the first in filled.
    anyone can help me with some ideas or suggestions.
    i have lookes a lot on web and tried to accomplish but stuck in middle of something.

    Regards

    A learner

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    If you want to stop the User from going to the 2nd field on your Input Form if the first field is not filled in - what you can do is put some code in the GotFocus event of the second field of your Form - something like this:

    Code:
    Private Sub ControlName2_GotFocus()
    
    Me.ControlName1.SetFocus
    If Me.ControlName1.Text = "" Then
        MsgBox "Please enter a value in the Text box."
        Me.ControlName1.SetFocus
    End If
    
    End Sub
    What I sometimes do, is to put the Code in the 'Save' or 'Submit' button of the Form and then check all the fields to make sure they have legitimate values . . .
    Hope this helps!!

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Robeen View Post

    ...put some code in the GotFocus event of the second field of your Form - something like this:

    Code:
    Private Sub ControlName2_GotFocus()
    
    Me.ControlName1.SetFocus
    If Me.ControlName1.Text = "" Then
        MsgBox "Please enter a value in the Text box."
        Me.ControlName1.SetFocus
    End If
    
    End Sub
    What I sometimes do, is to put the Code in the 'Save' or 'Submit' button of the Form and then check all the fields to make sure they have legitimate values . . .

    There are several things wrong with this answer/approach!


    1. If the object here is to make sure that the first Control is populated, what happens if they skip the first Control...and the second Control?
    2. The test If Me.ControlName1.Text = "" will fail about 999 times out of 1000! This is only testing for a Zero-Length String (ZLS), it does not test for a Null, which is what an 'empty' Control usually contains!
    3. Also, you cannot refer to the .Text Property of a Control, unless the Control has Focus; in this circumstance you have to use the .Value Property!
    4. Putting this kind of code in a 'Save' or 'Submit' button, both of which are unnecessary, in an Access Database, will not keep the Record from being saved, even if the Field is empty, because a Command Button does not have a Cancel event that can be used to Cancel the update if the data is missing or invalid. Validation to assure that a Field is populated has to be in the Form_BeforeUpdate event, which does have a Cancel event, so that saving the Record can be put on hold until the omission is corrected.


    The problem mentioned in #2 and #3, above, can be corrected in a couple of ways, all of which test for both Null and ZLS. Here's one:

    If Nz(Me.ControlName1.Value, "") = "" Then

    Now, before giving a definitive answer your question, we need to know if your sole purpose is to insure that the first Control has data before the Record is saved, or if it does, in fact, have to be populated before data is entered into the second Control. And if the latter is true, do both of these Controls have to be populated before saving the Record?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    tariq nawaz is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    31
    Quote Originally Posted by Missinglinq View Post
    There are several things wrong with this answer/approach!


    1. If the object here is to make sure that the first Control is populated, what happens if they skip the first Control...and the second Control?
    2. The test If Me.ControlName1.Text = "" will fail about 999 times out of 1000! This is only testing for a Zero-Length String (ZLS), it does not test for a Null, which is what an 'empty' Control usually contains!
    3. Also, you cannot refer to the .Text Property of a Control, unless the Control has Focus; in this circumstance you have to use the .Value Property!
    4. Putting this kind of code in a 'Save' or 'Submit' button, both of which are unnecessary, in an Access Database, will not keep the Record from being saved, even if the Field is empty, because a Command Button does not have a Cancel event that can be used to Cancel the update if the data is missing or invalid. Validation to assure that a Field is populated has to be in the Form_BeforeUpdate event, which does have a Cancel event, so that saving the Record can be put on hold until the omission is corrected.


    The problem mentioned in #2 and #3, above, can be corrected in a couple of ways, all of which test for both Null and ZLS. Here's one:

    If Nz(Me.ControlName1.Value, "") = "" Then

    Now, before giving a definitive answer your question, we need to know if your sole purpose is to insure that the first Control has data before the Record is saved, or if it does, in fact, have to be populated before data is entered into the second Control. And if the latter is true, do both of these Controls have to be populated before saving the Record?

    Linq ;0)>

    yes i want a strategy that the user cannot go to 2nd control until data is not entered into the first control.and i don't want the record to be saved until both the records are on the form.
    i have my form bound to a table which automatically keeps updating the records. if i drop the control source values so that the values are not updated and then run a query in background of save button which saves the record on actual table.
    sorry i am having a lot of questions but i am learning things and want the things in better way as possible .
    if you can refer me any book which is specifically for forms and VBA coding i will be grateful for that.
    i am really really thankful to you guys.

    Regards

    A learner

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by tariq nawaz View Post

    ...i have my form bound to a table which automatically keeps updating the records...
    Is the Form in question Bound to an underlying Table or Query?

    Quote Originally Posted by tariq nawaz View Post

    ...if i drop the control source values so that the values are not updated...
    Sorry, I have no idea what you're trying to say, here! Please try to explain again.

    Quote Originally Posted by tariq nawaz View Post

    ...then run a query in background of save button which saves the record on actual table...
    This makes little sense, either! Why do you have a 'Save' button? Access automatically saves a Record when you move to another Record or Close the Form.

    The main thing that a 'save' button on an Access database does is create unnecessary problems.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    tariq nawaz is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    31
    ignore my bound and unbound form question as i have already sorted that. thanks this forum and you guys.
    still need issues with how to validate that all the values are there.
    actually i have different options and depending on them some of my fields will be blank.
    i have table with vendor_name, vendor_number , service, weight, detination, end_cust_name, postcode, tracking_number, zone, region
    so for exmple if service=BFPO_Packet then i need that these fields should be there before saving: vendor_name, vendor_number , service, weight
    if service =Airsure then i need then i need that these fields should be there before saving:vendor_name, vendor_number , service, weight, detination, tracking_number, zone, region

    i am thinking for having some code in save button and if statement that if service is airsure and these fields are not null enable to save.

    will be highly appreciated if you guys can give me exact code which i can use in save button background.

    Regards

    A learner

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 08-02-2012, 02:53 PM
  2. How to Implement??
    By radick201 in forum Database Design
    Replies: 3
    Last Post: 01-15-2012, 02:02 AM
  3. implement expressions
    By quandore in forum Access
    Replies: 7
    Last Post: 01-11-2012, 03:48 AM
  4. How would I implement this?
    By redfox1160 in forum Access
    Replies: 4
    Last Post: 03-09-2011, 03:07 PM
  5. Replies: 2
    Last Post: 03-14-2010, 08:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums