Results 1 to 3 of 3
  1. #1
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131

    Replace Data Where Field is not blank

    I would like to write VB code for the following table. Where ever ticker is blank, replace it wth the Company from above. For example;
    I would like to Put Company 1 in the MoneyManager field below it for the 3 Stocks
    Then when the program finds a blank Ticker it would take the Company Field where that blank Ticker is and Replace it with the corresponding Company.
    Can this be done?

    ID Company MoneyManager Ticker Value (USD, mm) Shares Change %S/O %Portfolio Position Date Position Source Remove
    10573 Company 1










    False
    10574 Stock 1
    STX1 0.15 22,200 22,200 0.06 0.04 9/30/2016 13 F False
    10575 Stock 2
    STX2 0.58 129,725 63,500 0.1 0.14 9/30/2016 13 F False
    10576 Stock 3
    STX3 0 0 -14,906 0 0 9/30/2016 13 F False
    10577 Company 2








    False
    10578 Stock 1
    STX1 1.7 246,440 246,440 0.62 0.05 9/30/2016 13 F False
    10579 Stock 2
    STX2 1.76 53,740 53,740 0.18 0.05 9/30/2016 13 F False
    10580 Company 3








    False
    10581 Stock 1
    STX2 0.22 11,618 -3,939 0.03 0.02 9/30/2016 13 F False
    10582 Comapany 4








    False
    10583 Stock 1
    STX1 1.2 221,046 -7,000 0.66 0.43 9/30/2016 13 F False

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    You DONT write vb code, you create an update query.
    this will update fields where [field] is null.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    looks like you have an excel style of data storage which won't work in a database.

    Yo will need something to identify the previous row which has a company in it. If your ID field is to be relied on to indicate an order, it can be identified as the maximum ID where ID<=current ID and ticker is null

    so something like

    SELECT *, (SELECT TOP 1 Company FROM myTable T WHERE ID<=C.ID AND ticker is null ORDER BY ID desc) AS MoneyManager
    FROM myTable C
    order by ID

    strongly advise you do not mix companies and stocks in the same column and many of your calculations should be calculated in a query, form or report, not in the table. Perhaps this in an exercise to correct this?

    Other things to consider, do not use non alpha numeric characters in table or field names - ()%,/ etc - they all have uses in code so using them in field names will cause problems

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

Similar Threads

  1. Replies: 7
    Last Post: 04-15-2015, 09:14 AM
  2. Replies: 7
    Last Post: 08-06-2014, 05:38 PM
  3. Replies: 3
    Last Post: 07-30-2013, 12:11 PM
  4. Querying All Data When Form Field Is Blank
    By jre1229 in forum Queries
    Replies: 25
    Last Post: 08-22-2012, 11:32 AM
  5. Copy data into a blank field
    By winterh in forum Database Design
    Replies: 2
    Last Post: 04-16-2012, 04:57 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