Solved

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

Posted on 2013-01-09
3
484 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
  • 2
3 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now