
I would use VBA code in the form’s on current event to set the control’s Visible property.
Me.[NewField].Visible = Me.Fanart
You would want a similar line of code in the After Update of the Fanart control.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have no experience with database design or coding at all and I'm trying to teach myself Access in order to keep track of all my art.
I want to design the form so that, if the yes/no box for "fanart" is checked, a new field appears, prompting the user to enter the source material. If it's unchecked, the field stays hidden and the source material field in my database stays empty. How do I do that?
Kind regards and thanks in advance!
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
I would use VBA code in the form’s on current event to set the control’s Visible property.
Me.[NewField].Visible = Me.Fanart
You would want a similar line of code in the After Update of the Fanart control.
One approach is to use code in the Current event of the Form. Something like:
Me.SourceMaterial.Visible=Me.Fanart
I would recommend you step back from interface design for the time being.
The fundamental principle of a good Access database is proper table design.
The process by which we design and build the tables for a relational database is called "Normalization".
Here is a starter article to orient you to the principles.
Here is one of a number of good YouTube videos, again for starting out.
Note that neither source is highly technical, but for beginners, it's a good place to start.
Ken Sheridan, who is a principal participant here also has a lot of good sample databases illustrating Normalization. Unfortunately, I can't get the link to his Public OneDrive to work at the moment. Ken?
In this case, you want to eliminate that checkbox and use only the field for source material. If you enter something in it, that's the logical equivalent of checking "yes", and vice versa. The checkbox adds nothing to the quality of the data and only adds complexity to an interface while opening the door to data discrepancies. You'll understand that better when you've spent some time learning more about designing and building relational tables for an Access database applicaiton.
In relational database terms there is probably a one-to-many relationship type between Artworks and Sources, i.e. each artwork can be inspired by zero or one source, and each source might inspire one or more artworks. This would normally be modelled by two tables, Artworks and Sources.
As an artwork’s being fanart is an optional attribute, the best way to model the relationship type, however, would be by means of a third table. Normally this would be done to model a many-to-many relationship type, but in cases like yours, to avoid having an excessive number of Null SourceID column positions in rows in Artworks, modelling the one-to-many relationship type by separate table is recommended by Chris Date, who along with Ted Codd, was one of the founding fathers of the database relational model.
The table would be like this:
FanArtSources
….ArtworkID (long integer number primary key column)
….Source ID (long integer number foreign key column, indexed non-uniquely (Duplicates allowed))
By virtue of the ArtworkID foreign key column also being the primary key of the table, the relationship type between Artworks and FanArtSources is one-to-one, whereas that between Sources and FanArtSources is one-to-many. The FanArtSources table might have other non-key columns representing attributes of the relationship type. These might include a long text Notes column to allow for the entry of descriptive text about the relationship between the current artwork and the referenced source. Attributes of the source itself would be represented by non-key columns in Sources.
The user interface for this would be an Artworks subform within which is a FanArtSources subform based on a query which joins the FanArtSources and Sources tables on the SourceID columns. The subform would be linked to the parent form on ArtworkID, and would contain a combo box bound to the SourceID foreign key column in FanArtSources, set up as follows:
ControlSource: SourceID
RowSource: SELECT SourceID, Source FROM Sources ORDER BY Source;
BoundColumn: 1
ColumnCount: 2
ColumnWidths: 0cm
If your units of measurement are imperial rather than metric Access will automatically convert the unit of the last one to inches. The important thing is that the dimension is zero to hide the first column.
Addditional controls in the subform would be bound to any other non-key columns in FanArtSources. Other controls would be bound to whatever non-key columns from Sources whose values you might want to show inn the subform when a source is selected in the combo box. The Locked property of these controls should be set to True (Yes) to make them read-only.
To add a new source not currently represented in the Sources table you can use the NotInList event procedure of the Sources combo box to open a form for entering a new source record when a new source name is typed into the comb box. The code for the NotInList event procedure would be like this:
Dim ctrl As Control
Dim strMessage As String
Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"
If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmSources", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
' ensure frmSources closed
DoCmd.Close acForm, "frmSources"
' ensure Source has been added
If Not IsNull(Dlookup("SourceID", "Sources", "Source = """ & NewData & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Sources table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If
In the Open event procedure of the frmSources form you’d put the following code:
If Not IsNull(Me.OpenArgs) Then
Me.Source.DefaultValue = """" & Me.OpenArgs & """"
End If
where Source is the name of a text box control bound to the Source column. This will insert the value you typed into the combo box into the Source control ready for you to enter any other data into other bound controls in the form.
In the parent Artworks form you could hide/show the subform control if you wished, as described in the other responses you have received. Generally, however, it would be just left empty if no source is to be entered.
As you are new to Access you might like to take a look at DatabaseBasics.zip in my Dropbox public databases folder at:
This little demo file, as its name suggests, provides a simple introduction to some of the principles and methodologies for designing a relational database in Access.
I can't get the link to his Public OneDrive to work at the moment. Ken?
I've had so much trouble with people accesssing my OneDrive folder that I now give the link to my Dropbox folder: