Solved

Set Default Values in Microsoft Access Table w/ VBA

Posted on 2011-03-12
5
361 Views
Last Modified: 2012-05-11
With a Microsoft Access Form, I have 4 text boxes for the user to enter their Name, Department, Title, and Manager Name.  
Using VBA, I want to take each of those 4 values and set the default values of 4 fields in a table.  The form that opens up is not bound to the table for which I want to set up the default values for.
0
Comment
Question by:vfinato
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 75
ID: 35118819
Form is not bound ?  Just curious why?

Anyway ... you can use DLookup() to do this ... and probably in the Form Load event, or possibly from a New Record button ...

Me.Text1 = DLookup("[Field1]","[YourTableName]", <optionalCriteriaHere>)

mx
0
 
LVL 75
ID: 35118834
OR  ... just


Me.Text1 = "YourDepartmentName"

and so on ... if you just want to hard code these values.  The first post 'looks up' values from a table.

mx
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 35121173
Do you mean you want to set the Default PROPERTY of Fields at table level? If so, you can do this:

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb
Set tdf = dbs.TableDefs("YourTableDef")
Set fld = tdf.Fields("YourField")

fld.DefaultValue = "Your Value"
0
 

Author Closing Comment

by:vfinato
ID: 35148140
Actually, I am using ADO (which I forgot to mention in the original post).  Here is a snippet of the ADO/SQL code that I used to accomplish this task.

        Dim str1 As String
        Dim strDblQuote1 As String
        Dim strDblQuote2 As String
        strDblQuote1 = """"
        strDblQuote2 = """"

str1 = "ALTER TABLE StartingNumberTable ALTER COLUMN [LeadAuditor] CHAR (50) Default " & strDblQuote1 & strLeadAuditor & strDblQuote1
        cnCon.Execute str1
0
 
LVL 75
ID: 35149890
vfinato
For future reference, next time try to explain a little better what you are trying to do ... and more importantly, please take the time to response to Expert comments.   I took the time to give you two solutions and you gave No response.

mx
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question