?
Solved

Use VBScript In Access To Add Another Column and Populate It's Rows

Posted on 2013-01-09
3
Medium Priority
?
529 Views
Last Modified: 2013-01-14
I have a table that has a Name column with stuff like "$25 Gift Card".

I need to add another column to the table of type Number with the 25.

I was thinking of using VBscript but, not sure how to actually pull the name, split it and stuff the 25 into the same row.

There are about 140000 rows and possibly more depending.

Any ideas or pointers?
0
Comment
Question by:cefranklin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38759401
you can use a user defined function to that

place this codes in a regular module

function getNumValue(xCol)
if xcol & ""="" then getNumValue=null : exit function

getNumvalue=split(xcol," ")(0)

end function

now run a query

select ColumnName, getNumvalue([ColumName]) as newCol
from tableName


basically, that is the general idea.. you may need to tweak the codes depending on the output you want and the manner the data was inputted
0
 
LVL 2

Accepted Solution

by:
cefranklin earned 0 total points
ID: 38759449
Kind of funny that I just posted this and figured it out.  I am using the Mid() function for SQL then altering the column to a number type to get rid of any spaces.

q_SalesByDate = "" & _
        "SELECT V_SITE.SITENAME, V_SALE.SITE, V_ITEM.NAME, V_ITEM.GLACCOUNT, V_SALE.LOGDATE, Mid([V_SALEITEMS].[NOTE],1,7) AS [NOTE], Mid([V_ITEM].[NAME],2,3) AS [TOTAL] " & _
        "INTO T_SalesByDate " & _
        "FROM ((V_SALE " & _
        "INNER JOIN V_SALEITEMS ON (V_SALE.OBJID = V_SALEITEMS.SALEID) " & _
        "AND (V_SALE.SITE = V_SALEITEMS.SITE)) " & _
        "INNER JOIN V_SITE ON (V_SALEITEMS.SITE = V_SITE.ID) AND (V_SALE.SITE = V_SITE.ID)) " & _
        "INNER JOIN V_ITEM ON V_SALEITEMS.ITEM = V_ITEM.OBJID " & _
        "WHERE (((" & sites & ") " & _
        "AND (" & giftcards & ") " & _
        "AND ((V_SALE.LOGDATE) Between #" & Me.txtFromDate.Value & "# And #" & Me.txtToDate.Value & "#)) " & _
        "ORDER BY V_SALE.LOGDATE DESC;"
    
    
    'MsgBox q_SalesByDate
    DoCmd.RunSQL q_SalesByDate
    
    q_FixTotalColumnInSales = "ALTER TABLE T_SalesByDate ALTER COLUMN TOTAL NUMBER;"
    
    DoCmd.RunSQL q_FixTotalColumnInSales

Open in new window

0
 
LVL 2

Author Closing Comment

by:cefranklin
ID: 38773801
Figured it out myself, sorry.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question