[AccessD] Setting default value of a text box

Kaup, Chester Chester_Kaup at kindermorgan.com
Wed Apr 3 08:42:47 CDT 2013


The reason for doing this is that if the invoice is from Gus Services the invoice number has no prefix. If the invoice is from Renegade it always has the prefix RWLS. Just trying to eliminate some data entry.

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

If you're at this point, can't you just assign the actual value of this field to  = IIf(Company = "Renegade", "RWLS", Null), rather than trying to set the default value?


Private Sub CompanyName_AfterUpdate()
    Dim Company As String
    Dim varInvoiceNumber as variant

    Company = Me.CompanyName.Value
    'Me.[Invoice Number].DefaultValue = IIf(Company = "Renegade", "RWLS", Null)
    If CompanyName = "Renegade" then varInvoiceNumber = "RWLS"
    txtInvoiceNumber = varInvoiceNumber

End Sub



Carolyn Johnson




  ----- Original Message ----- 
  From: Kaup, Chester 
  To: Access Developers discussion and problem solving 
  Sent: Wednesday, April 03, 2013 8:23 AM
  Subject: 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

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

  That will always return Null since the Default Value is created in the textbox of a new record before any user selection takes place.

  You need to put code to specifically set the actual value in an event that triggers after the selection is made in the Listbox.  Possibly

  Sub On_txtInvoiceEnter()
  txtInvoice = IIf([CompanyName].[Value]="Renegade","RWLS",Null)
  End Sub



  On 2 Apr 2013 at 14:49, Kaup, Chester wrote:

  > I have a data entry form. The first entry is a list box where the user 
  > selects a company name. List box name is companyname. The next data 
  > entry is an invoice number. I am trying to set the default value 
  > property of the text box using the following statement. The default 
  > value is not becoming part of the saved data. Thanks for the help
  > 
  > =IIf([CompanyName].[Value]="Renegade","RWLS",Null)
  > 
  > I also tried
  > =IIf([CompanyName]="Renegade","RWLS",Null)
  > 
  > Do I maybe need to set it using code in the after update event of the list box?
  > --
  > 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
-- 
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