Results 1 to 11 of 11
  1. #1
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6

    Aplication form

    I’m creating a application form for admin and user'sto use. I created textboxes for username and password, and 2 buttons (Ok and Cancel).Button OK includes ACCESS VBA for entry in the application. Everything works fine,but I want to enable, when user write the username and password and press ENTERto automatically processed like if he would press the OK button. Right now Ineed the press if I want to enter in the application.
    Thank you in advance for any help you can provide. Roman




  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    in both boxes afterupdate event, username and password,
    put RunLogin , since the user can fill out the boxes in any order

    Code:
    sub txtUser_afterupdate()
       RunLogin
    end sub
    
    sub txtPass_afterupdate()
       RunLogin
    end sub
    
    sub    RunLogin()
       if not IsNull(txtUser) and not IsNull(txtPass) then
             'code to check the login
      endif
    end sub

  3. #3
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6
    Sorry, but.....
    ... don't work it.

    Private Sub txtLoginID_AfterUpdate()
    Run Ukaz1 'trying runUkaz1 too
    End Sub
    ----------
    Sub txtPassword_AfterUpdate()
    Run Ukaz1
    End Sub
    -----------
    Where is place for:
    sub RunLogin()
    if not IsNull(txtUser) and not IsNull(txtPass) then
    'code to check the login
    endif
    end sub

    Access VBA procedure is located in (On Click)

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Hi Roman,

    You can check the following post https://stackoverflow.com/questions/...-submit-button

    You need to set the default property of the OK button to Yes and make sure that that is the button that receives focus after the Password textbox.

    To use ranman256's code you need to use Call cmdOK_OnClick or whatever you called the OK button.

    Cheers,
    Vlad

  5. #5
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6
    Hi Vladan,
    The Key Preview =True That's it!
    But…
    Where to insert this procedure in the properties of thebutton (which form; txt_pasword or txt_OK and place in properties ofbox))
    How to correctly write this sentence;
    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturnthen
    ...Submit script
    End If
    End Sub

    This step of my project is already a nightmare!
    Thank you for your help!
    Roman

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Hi Roman,

    If you know that the OK button will have the focus when the Enter key is pressed then all you need to do is to set its "Default" property to Yes (look on the "Other" tab of the Properties window of the command button itself.

    To use the form's OnKeyPress event you need to put the first line of code in the OnLoad event of the form (Key Preview=Yes)

    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturnthen
    Call cmdOK_OnClick
    End If
    End Sub
    Keep in mind that this will run the code behind the button every time Enter is pressed, even if the user or password boxes are not yet populated, so you need to account for that in your code.

    Cheers,
    Vlad

  7. #7
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6
    Vlad, thank you for your time.

    Property KeyPrevisevs= Yes / OK!
    Textbox has only property; Enter key behavior; Default or New line in field

    Error;
    Click image for larger version. 

Name:	access_error.jpg 
Views:	23 
Size:	53.2 KB 
ID:	33825

    Private Sub Form_Load(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
    Call cmdOK_OnClick
    End If
    End Sub

    Cheers, Roman

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Roman,
    Not sure I follow you; you need to set the property "Default" of the OK command button to Yes, not sure what textbox you are referring to. You can put your form in an empty Access file and upload it here so we could have a look.

    Cheers,
    Vlad

  9. #9
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6

    application form


  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    Hi Roman,
    Have a look at the form now and see if that is what you wanted.
    Cheers,
    Vlad
    Attached Files Attached Files

  11. #11
    romanl is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2018
    Posts
    6
    It's working!

    Thank you for your assistance.
    With respect!
    Roman

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

Similar Threads

  1. Shortcut Icon for an Access Aplication
    By Robert2150 in forum Access
    Replies: 8
    Last Post: 04-12-2018, 04:03 PM
  2. Replies: 4
    Last Post: 09-20-2012, 04:01 PM

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