Results 1 to 8 of 8
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    dlookup as default value

    I am not sure what I am doing wrong. This form after updating populates a series of fields from table data and that works fine. But I want the tax rate to be set to the default value of another table titled "Tbl_salesTaxRate". This table has 2 fields, the tax rate data and a checkbox so the user can set what tax rate should be the default.
    I have also tried setting the dlookup to the taxRate field's default value property, but that was a no go as well. Any help here would be greatly appreciated.
    I should also mention that I made sure that I have a value set to True in the Tbl_salesTaxRate table.

    Private Sub Combo31_AfterUpdate()


    Me.UnitPrice = Me.Combo31.Column(2)
    Me.Taxable = Me.Combo31.Column(3)
    Me.Description = Me.Combo31.Column(1)
    Me.Category = Me.Combo31.Column(4)

    If [Taxable] = True Then
    Me.TaxRate = DLookup("SalesTaxRate", "Tbl_SalesTaxRate", "DefaultValue=TRUE")
    End If

    DoCmd.GoToRecord , , acNewRec
    End Sub

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    Try
    Me.TaxRate = DLookup("SalesTaxRate", "Tbl_SalesTaxRate", "DefaultValue=-1")

    Is Defaultvalue the name of the other field?

  3. #3
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    DefaultValue in the expression is referring to a field named DefaultValue in the table, correct?

  4. #4
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    Or try
    Me.TaxRate = DLookup("SalesTaxRate", "Tbl_SalesTaxRate", "DefaultValue='TRUE'")

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Is DefaultValue a Yes/No or Text datatype?

    Are there many records in Tbl_salesTaxRate that are 'True'? If so, then need more criteria to narrow down the search. DLookup will return value from first record meeting criteria.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Yes, DefaultValue is a field name in the table.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    More questions in post 5.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    I am pleased and embarrassed to say that I figured it out. Turns out my code was correct but my data type was not matching between my form and my table.
    The error message never said "miss matched data type", it just returned a compile error, kind of frustrating how much time was spent on this, sorry about that to those who helped.
    However, knowing that "DLookup will return value from first record meeting criteria." is something I did not know and will come in very helpful, thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Default Value
    By Njliven in forum Access
    Replies: 1
    Last Post: 10-10-2012, 12:48 PM
  2. Primary key default value
    By mjackman in forum Access
    Replies: 1
    Last Post: 04-30-2012, 07:10 AM
  3. Set default value
    By accessnewb in forum Programming
    Replies: 3
    Last Post: 08-17-2011, 06:24 PM
  4. Default value
    By Hatye in forum Access
    Replies: 1
    Last Post: 06-19-2011, 05:16 PM
  5. Default value a DLookup?
    By Lockrin in forum Access
    Replies: 1
    Last Post: 07-01-2010, 08:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums