Solved

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

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
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 …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

690 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