Disabling Fields on a form

  • Thread starter Thread starter Qwijibo
  • Start date Start date
Q

Qwijibo

Hi I've got an A-Level Computing Projet to do and I need to know how to
disable a field on a form while the criteria isn't there.
I want to disable a textbox from having anything typed into it if the
the term "shot" is not selected from a list box in the same form.
(Seperate tables with a primary-foreign key relationship)

Eg/ The user inputs the data for a drink into the form and selects
"bottle" from a list of different types of drinks. The textbox called
"price per shot" would be disabled at this point (or from the start
until "shot" is chosen) so nothing can be entered into it. In a new
record the data is entered and the "Type of Drink" is a "shot" so I
want the textbox "price per shot" to be active and able to have data
entered.

Please give me some advice on how to do this - in vba, sql or just
normally - it doesn't matter. Thanks.
Gavin Thompson.
 
It certainly sounds as if your are designing a non-relational database. You
should probably rethink your database design. Having a separate textbox,
hence a separate underlying field bound to "price per shot" would yield a
highly un-notmalized database structure. How about something like:

tblBeverages
BeverageID
BeverageName

tblUnits
UnitID
UnitName

tblBeverageDetails
BeverageID
UnitID
Price

In your form, have a list or combo box to collect the BeverageID and UnitID,
and add the price after choosing the first 2.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
No, its just a bit of code I need adapting to fit the scenario. In my
teacher's exemplar answer for the last bit of coursework at AS level it
disabled a listbox on the form after the data was entered so you
couldn't change it. I just want to disable my textbox unless a certain
criteria is satisfied. I.e. There's no need for data to be entered, so
you can't.
I want the textbox "price per shot" to not accept any data if you
haven't selected "shot" from the "Type of Drink" list box.
Thanks.

P.S. It is a relational database - I have several relationships between
each tables. Like BeverageID (primary key) to another BeverageID
(foreign key) in another table.
 
If it is relational, the list box will have a key for each row of data. For
now, let's call it PrimeKey (for Primary Key). So, if the value of PrimeKey
for the "shot" description is 3, the code would looke like:

Sub Type_Of_Drink_ AfterUpdate()
If Me.[Type Of Drink] = 3 Then
Me.[Price per Shot].Locked = True
Else
Me.[Price per Shot].Locked = False
End If
End Sub

You also need to call this in the form's Current event so it will lock the
textbox when you are scrolling through records.

Sub Form_Current()
Type_Of_Drink_ AfterUpdate
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top