Solved

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

Posted on 2013-01-09
3
508 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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