Link to home
Start Free TrialLog in
Avatar of Vince
VinceFlag for United States of America

asked on

Set Default Values in Microsoft Access Table w/ VBA

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.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

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
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
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vince

ASKER

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
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