BFreshour
Programmer
- Mar 20, 2002
- 84
I have an Access form and I'm trying to set a ControlSource for an unbound textbox either from prompting the user (just one time) or by querying a table for the information.
I used an OnLoad code that would test to see if txtTeamAbbv.ControlSource = "", if it did it would send an inputbox to the user asking for their abbreviation. It then ran a DoCmd.Save acForm. That seemed to work, but it would never save. Each time the form was loaded it would ask the user, so it obviously wasn't saving the txtTeamAbbv.ControlSource.
Then I thought about having a 'settings' table and running a query to get the first record, teamabbv column and set the ControlSource that way. However I can't figure out how to run a query and get that value...
Can anyone help?
Here is the code I was trying to use:
I used an OnLoad code that would test to see if txtTeamAbbv.ControlSource = "", if it did it would send an inputbox to the user asking for their abbreviation. It then ran a DoCmd.Save acForm. That seemed to work, but it would never save. Each time the form was loaded it would ask the user, so it obviously wasn't saving the txtTeamAbbv.ControlSource.
Then I thought about having a 'settings' table and running a query to get the first record, teamabbv column and set the ControlSource that way. However I can't figure out how to run a query and get that value...
Can anyone help?
Here is the code I was trying to use:
Code:
If (txtTeamAbbv.ControlSource = "NA") Then
TeamAbbv = InputBox("What is your team's abbreviation? (3 characters MAX)", "Team Abbreviation", "OKC")
TeamAbbv = "='" & TeamAbbv & "'"
txtTeamAbbv.ControlSource = TeamAbbv
DoCmd.Save acForm, "Offensive Packages"
End If