Setting Default Values for all fields in a table

MrAccessUniversity

New Member
Joined
Nov 28, 2011
Messages
3
I recently learned how to set default values for all fields in a table using VB (DAO).

Public Sub Make_defs()

Dim x As Integer

For x = 1 To CurrentDb.TableDefs("import_format").Fields.Count
CurrentDb.TableDefs("import_format").Fields(x - 1).DefaultValue = "=null"
Next

End Sub

I had a table used for importing data into an application and most of the fields default values were a literal string "null". This code was quite simple but most of the samples found on other forums were useless.:biggrin:
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The default value for fields is normally Null for none numeric fields. Why would you need to specifically set it to Null for non numeric fields?
 
Upvote 0
The table was used for creating an import file into another application for data conversion. Many of the columns of data in the import specification were not required and were set to null. In the receiving application, you had to pass literally the word <'null'> as a string.
 
Upvote 0
The table was used for creating an import file into another application for data conversion. Many of the columns of data in the import specification were not required and were set to null. In the receiving application, you had to pass literally the word <'null'> as a string.

Ah .. that makes sense. I have had to deal with import/export between system that had similar requirements.

Glad you found a working solution. Thanks for sharing. :)
 
Upvote 0
You were right. The prescribed solution didn't make sense because all columns are by default null (empty). By the way, the illustrated text <'null'> is just an example. There is nothing specifically useful about how the string is formatted using the single quotes inside the brackets. Don't know why it took me so long to figure out such an easy way of doing it. I spent hours running down tables using the Access table designer to set default values for such tables.

:cool:
 
Upvote 0

Forum statistics

Threads
1,215,689
Messages
6,126,217
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top