Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Default Value for Fields on Table

Status
Not open for further replies.

bzsurf03

MIS
Dec 13, 2002
75
0
0
US
I am familiar with VBA for Excel, but seem a little lost with Access, so plan assumptions accordingly.

I was able to automate most of my process using Access Macros, but some functionality still isn't there. Basically, I am running a Macro which kicks off a series of "Sub-macros". One of these Sub-macros will be a "RunModule" action. This module is currently prompting for three inputs using three input boxes which are collected in variables. I want to assign these variables to the default values of three different fields. These will serve as parameters right before I run an Append query to this table.

So simply put. What is the syntax to define the Default Value property of a field on a table? Do I need to connect to the database first or am I already connected by already having it open?
 
bzsurf03
You're already connected. Here's a snippet that will set the default value of a single field to the value of a textbox:

Code:
Private Sub setdefault()
Dim db As Database
Dim tdf As TableDef
Set db = CurrentDb
Set tdf = db.TableDefs("CUST2")
tdf.Fields("CUST_NBR").DefaultValue = Forms!myform.CUST_NBR
End Sub

Good luck
Tranman

"Adam was not alone in the Garden of Eden, however,...much is due to Eve, the first woman, and Satan, the first consultant." Mark Twain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top