[AccessD] Setting default value of a text box

Kaup, Chester Chester_Kaup at kindermorgan.com
Wed Apr 3 16:01:39 CDT 2013


That worked. Thanks to everyone for your help and the lesson.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Wednesday, April 03, 2013 3:45 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Setting default value of a text box

No, DefaultValue is what Access puts in the empty field when data entry is started on a new record.

If you want to save typing then you need something like:

Private Sub Invoice_Number_AfterUpdate()
    If Company = "Renegade" and  Left$([Invoice Number],4) <> "RWLS" Then
              [Invoice Number] =  "RWLS"  & [Invoice Number]
    End If
End Sub


On 3 Apr 2013 at 18:44, Kaup, Chester wrote:

> The code runs but returns the value ""RWLS"" to Me.[Invoice 
> Number].DefaultValue. My understanding is that if a text box is 
> assigned a default value any additional characters typed into the text 
> box would be appended to the default value. For example if 1234 is 
> entered then Invoice Number in the underlying table should have the 
> value RWLS1234 but only 1234 is being stored. I am confused.
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com 
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav 
> Brock
> Sent: Wednesday, April 03, 2013 11:43 AM
> To: 'Access Developers discussion and problem solving'
> Subject: Re: [AccessD] Setting default value of a text box
> 
> Hi Chester
> 
> You probably need a set of outer quotes:
> 
> Private Sub CompanyName_AfterUpdate()
>     Dim Company As String
>     Company = Me.CompanyName.Value
>     Me.[Invoice Number].DefaultValue = IIf(Company = "Renegade", 
> Chr(34) & "RWLS" & Chr(34), "") End Sub
> 
> /gustav
> 
> 
> -----Oprindelig meddelelse-----
> Fra: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] På vegne af Kaup, 
> Chester
> Sendt: 3. april 2013 15:23
> Til: Access Developers discussion and problem solving
> Emne: Re: [AccessD] Setting default value of a text box
> 
> I tried placing the following code in the after update event of the text box Company Name but it seems to do nothing. This is the first text box on the form that accepts data. What am I doing wrong?
> 
> Private Sub CompanyName_AfterUpdate()
>     Dim Company As String
>     Company = Me.CompanyName.Value
>     Me.[Invoice Number].DefaultValue = IIf(Company = "Renegade", 
> "RWLS",
> Null)
> End Sub
> 
> 
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 



-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list