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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,216,131
Messages
6,129,066
Members
449,485
Latest member
greggy

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