LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions,microsoft.public.sqlserver.datamining
external usenet poster
 
Posts: 64
Default Code to include a one-up suffix to a field value

I have the following INSERT statement (which works fine) -- what I need is
to modify it so that the value of the field "Location" will be passed to SQL
server with a one-up suffix (example: on the 1st pass, append "1" to the
location Dallas, to get "Dallas 1" on the 2nd pass, Dallas 2, ect -- ) to
track versions. I'm not sure how I would write the code to automatically
affix the next higher number. How would I go about doing this?

Many thanks in advance.

Here's my code:
========================================
Sub ProductData()

Dim oConn As Object
Dim sSQL As String

Application.ScreenUpdating = False
Set wsSheet = ActiveWorkbook.Sheets("Products")
Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=xxx.xx.xx;" & _
"Initial Catalog=Products;" & _
"User Id=xxxxx;" & _
"Password=xxxxx"

For i = 2 To Range("A65536").End(xlUp).Row
sSQL = "INSERT INTO Upload_Specific " & _
"([Location], [Product Type], [Quantity], [Product Name], [Style],
[Features]) " & _
" VALUES ('" & Range("A"&i).Value & "', '" & Range("B"&i).Value & "', '"
& _
Range("C"&i).Value & "', '" & Range("D"&i).Value & "', '" & _
Range("E"&i).Value & "', '" & _
Range("F"&i).Value & "')"
oConn.Execute sSQL
Next i


oConn.Close
Set oConn = Nothing


End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Help (Uppercase multiple ranges?) Ken Excel Discussion (Misc queries) 14 December 2nd 06 07:23 PM
copy and use vba code Giz New Users to Excel 6 November 24th 06 11:39 PM
copy and use vba code Giz Excel Discussion (Misc queries) 9 November 22nd 06 09:57 PM
Need help with Email Code (PLEASE) [email protected] Excel Worksheet Functions 4 October 21st 06 01:55 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"