Results 1 to 6 of 6
  1. #1
    GregFarrell is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    6

    Initialize field with a blank

    I am in the process of modifiying the MS Access sample database "Northwind" or use at a local not for profit orginzation. I have very limited MS Access skills.

    The subset of code below is from the Form "Order Subform for order details". In the field "Quanity" below, I would like the code to write a blank field rather than a "0".

    In other words, the line
    Me![Quantity]=0, should be something like Me![Quantity]=blank

    I have tried using "" , "empty" and a few others. I have also tried using default values of such as "". Any help will be appreciated.


    Private Sub Product_ID_AfterUpdate()
    'Initialize price and discount for each product change
    If Not IsNull(Me![Product ID]) Then
    Me![Quantity] = 0


    Me.Quantity.Locked = False
    Me![Unit Price] = GetWholesalePrice(Me![Product ID])
    Me![Discount] = 0
    Me![Status ID] = None_OrderItemStatus

    'Empty Product records mean user wants to delete line item
    Else
    eh.TryToRunCommand acCmdDeleteRecord
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Try

    Me![Quantity] = Null
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GregFarrell is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    6
    Thanks for the quick reply.
    I tried entering Null. I get an error message "You tried to assign the Null value that is not a variant data type.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    I suspect at the table level the Quantity field is set to not allow Nulls (Required = Yes), which is not necessarily a bad thing. You can try changing that, or live with the 0.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GregFarrell is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    6
    Solved! I neglected to check the table properties. The Quanity field had a default value of 0 in the table. I was also able to change it to Required = No. Thanks for the help!!!

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    Happy to help. Personally I would likely leave the required property as Yes, to prevent records with no quantity, but you can see how it works as is.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Converting dates from a field with blank records
    By NOTLguy in forum Programming
    Replies: 3
    Last Post: 10-14-2010, 06:38 AM
  2. Replies: 3
    Last Post: 09-15-2010, 01:04 PM
  3. Adding field to form causes blank view.
    By emccalment in forum Access
    Replies: 1
    Last Post: 04-02-2010, 06:27 PM
  4. Replies: 5
    Last Post: 09-16-2009, 05:22 PM
  5. Return blank field depending on quantity
    By anthonyjf in forum Access
    Replies: 1
    Last Post: 04-01-2009, 08:22 AM

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