Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving form values

Status
Not open for further replies.

anth1977

Programmer
Mar 17, 2002
5
US
I'm trying to write some basic code to pull the values of two text boxes on an access form. However, I have found the only way to do such is to first set the field's focus and then grab the values. This forces the user to see
the setfocus actions, and with 10 fields, that can be very annoying. Any suggestions? The code is in a VBA module.


Dim strusername as string, strpassword as string
txtusername.setfocus
strusername = txtusername.text
txtpassword.setfocus
strpassword = txtpassword.text

Thanks!

-Anthony
 
Try This instead

Dim strusername as string, strpassword as string
'txtusername.setfocus
strusername = txtusername.value
'txtpassword.setfocus
strpassword = txtpassword.value

This will read the contents of the text box with forceing you to set the focus
 
In my experience, SetFocus *is* required before changing the contents of a textbox (in code). Am I mistaken?

This is a different question than the thread. I am asking about writing to a text box, not reading from one.
 
Thanks, Jim - I'm unable to reproduce the problem now anyway; I suspect it was an issue with a prior Access version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top