Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2007, 02:16 PM
Authorized User
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Programmatically update field default value

Is there any way to set a new default value for records in a given field via VBA?

Thanks in advance

 
Old October 25th, 2007, 02:35 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in the form load event use:

me.fieldname.value=24

or

me.fieldname.value = date for today's date

me.fieldname.value="zyx" for a string etc


 
Old October 25th, 2007, 03:03 PM
Authorized User
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmm... i think i should rephrase that. is there a way to programmatically change the default value defined for a field within a given table? meaning... when new records are entered into the table, they will automatically default to the newly created default value for the field in question.

Thanks

 
Old October 25th, 2007, 03:12 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

basically the same thing

me.fieldname.defaultvalue="xyz"

 
Old October 25th, 2007, 03:22 PM
Authorized User
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cool. thanks, i'll try that out.

 
Old October 26th, 2007, 10:17 AM
Authorized User
 
Join Date: Oct 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I must be doing something wrong. I tried setting the 'Default Value' property for the field in question to:

Forms![frmUpdRate]![txtRate]

and tried saving the table. I got an error message:

"Could not find field 'Forms]![frmUpdRate]![txtRate'."

I also tried querying another table for the value using the following SQL:

select intrate from rate where entry = 1

I got an error message saying:

"The syntax of the subquery in this expression is incorrect.

Check the subquery's syntax and enclose the subquery in parentheses."

As you can see, there is no subquery to enclose in parentheses.

Any ideas? Thanks!

 
Old October 26th, 2007, 01:29 PM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok

Using your information of fields the code should be

Private Sub Form_Load()

  me.txtRate.DefaultValue=1
  'any other code you need to enter

end sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Field Values tachtenberg Reporting Services 1 February 19th, 2008 05:52 PM
Programmatically set update for one Gridview recor wirerider ASP.NET 2.0 Basics 5 February 11th, 2006 01:00 PM
Referring to a field and updating Programmatically vmerc Access VBA 4 January 12th, 2006 10:28 AM
Update city field based on zip field nganb SQL Server ASP 0 April 22nd, 2004 10:30 PM
Field Default lryckman Access 1 August 13th, 2003 07:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.