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 November 4th, 2004, 04:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default DefaultValue Property Setting Failing

What could cause the assignment of a default value to a text box or combo box in Access XP VBA to give a #Name? error? For example, I have a very simple declaration of

Me.txtMyField.DefaultValue = "Whatever"

When I open the form, instead of the default I specified, I'm getting the #Name? error in the text box. I'm getting the same error in a combo box in another form. Both syntaxes are quite simple and they are correct.

What gives?


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old November 6th, 2004, 06:51 AM
Authorized User
 
Join Date: Jul 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It seems .DefaultValue only works on a bound textbox not an unbound one.

Cheers Ray
 
Old November 8th, 2004, 09:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Actually, my fields are bound. Here is how this is solved. It makes no sense to me, but it works.

Me.txtMyField.DefaultValue = "'Whatever'"


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old April 2nd, 2007, 12:22 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


<quote>
Actually, my fields are bound. Here is how this is solved. It makes no sense to me, but it works.

Me.txtMyField.DefaultValue = "'Whatever'"
</quote>

Um... how is the solution different than the original problem code?


I'm having a similar problem. I have a bound field on a form, and I'm just trying to set its DefaultValue from the form's open event code:

Me.ProcurementTitle.DefaultValue = "hi"

This gives me #Error instead of "hi" when I open the form. Funny thing is I'm doing exactly the same thing on another form with another bound control and it works fine. Also, if I set DefaultValue to "hi" in the property sheet instead of from code, it works fine (I get "hi" instead of #error). Anyone know what's going on?




 
Old April 2nd, 2007, 12:23 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:Um... how is the solution different than the original problem code?


Sorry, stupid me I missed the single quotes.

 
Old April 2nd, 2007, 12:40 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Figured it out. In my case, the main problem was that my string data had a bunch of trailing spaces, so I had to use trim.

For the rest of you, the solution is to concatenate the double quotes in code. I have no idea when the double quotes are and and are not required, since I am doing it both ways in separate places with no obvious differences.

This is what worked for me:
Me.ProcurementTitle.DefaultValue = Chr(34) & Trim(strResult) & Chr(34)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting property value of class - objectdatasouce ranjan74feb ASP.NET 2.0 Professional 0 October 20th, 2007 03:51 AM
Setting "DBEngine.SystemDB" property jkuusik BOOK: Access 2003 VBA Programmer's Reference 2 December 28th, 2005 06:51 AM
Setting Property for a Custom Control cadaats C# 0 October 17th, 2005 02:22 AM
Setting ReadOnly Property Values Gavin265 General .NET 8 May 19th, 2005 12:49 PM
setting the ReadOnly property with a function creative_eye General .NET 3 May 10th, 2004 03:27 PM





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