Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2004, 05:32 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Biggladius Send a message via MSN to Biggladius
Default How can use sql syntax in excel vba

I want find in 40.000 lines in people name first 3-5 character or only name. anybody know how can i use sql syntax in excel vba?

 
Old October 5th, 2004, 03:11 AM
Authorized User
 
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What do you mean about: first 3-5 character or only name?
Characters: 3, 4 and 5?

 
Old October 5th, 2004, 10:11 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Biggladius Send a message via MSN to Biggladius
Default

Sorry about my bad english, actually i don't know how can i use sql syntax in excel vba,
About your question here is the example,
"id " ; "name surname" ......
234546 "marisa.scarafoni
234647 "tom.myster"
234748 "destiny..cruise.."
?????? "destiny....cruise." <=== ****
...... ...................
if i don't know his id, need to search by name&surname and all space is problem when the searching by name. i want to search by name first 4 letter or only name of his/her name area,

Quote:
quote:Originally posted by mushu
 What do you mean about: first 3-5 character or only name?
Characters: 3, 4 and 5?

 
Old October 5th, 2004, 11:14 AM
Authorized User
 
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Biggladius, don't worry about your English, I am sure mine is worst.

I send you an insert button that I use, please, notice that you have to change the name of your server and your database; and you would have to change for your own tables.

It is just an example to show you how to connect and disconnect, and how to write and insert statement.

Private Sub CmdInsert4_click()
'Insert Button

Dim cn As New ADODB.Connection
Dim rsInsertData As New ADODB.Recordset

Dim sConnStrTags As String
Dim stagname As String
Dim iValue As Integer
Dim sServer As String
Dim strInputValue As String

'Define server name
sServer = "SQLSERVER"

'make the connection to the database
sConnStrTags = "driver={SQL Server};server=" & sServer & _
        ";database=Runtime;uid=wwadmin;pwd=wwadmin"
'Runtime is the name of my database, and the user and password
cn.ConnectionString = sConnStrTags
cn.Open

'INSERT Data
Set rsInsertData = cn.Execute("INSERT into History(DateTime, TagName, Value, QualityDetail) " & _
                    "VALUES(getdate(), '" & stagname & "', " & iValue & ", 192)")
'History is the name of the table, and Datetime, Tagname, Value and Quelity datail the name of the columms.
'close the connection
If cn.State = 1 Then
    cn.Close
End If

End Sub


I hope it will help you.

 
Old October 6th, 2004, 04:15 AM
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Biggladius Send a message via MSN to Biggladius
Default

At first thank you for your help,
i sow you wanna show how to connection with sql server but,
how can i use sql syntax in excel macros?
you know in excel we have some functions and "ctrl+f" key combination as my need this is what i need.
 i think they are use some codes of sql when we search in excel sheet.
Thank you all your help again.

Quote:
quote:Originally posted by mushu
 Hi Biggladius, don't worry about your English, I am sure mine is worst.

I send you an insert button that I use, please, notice that you have to change the name of your server and your database; and you would have to change for your own tables.

It is just an example to show you how to connect and disconnect, and how to write and insert statement.

Private Sub CmdInsert4_click()
'Insert Button

Dim cn As New ADODB.Connection
Dim rsInsertData As New ADODB.Recordset

Dim sConnStrTags As String
Dim stagname As String
Dim iValue As Integer
Dim sServer As String
Dim strInputValue As String

'Define server name
sServer = "SQLSERVER"

'make the connection to the database
sConnStrTags = "driver={SQL Server};server=" & sServer & _
        ";database=Runtime;uid=wwadmin;pwd=wwadmin"
'Runtime is the name of my database, and the user and password
cn.ConnectionString = sConnStrTags
cn.Open

'INSERT Data
Set rsInsertData = cn.Execute("INSERT into History(DateTime, TagName, Value, QualityDetail) " & _
                    "VALUES(getdate(), '" & stagname & "', " & iValue & ", 192)")
'History is the name of the table, and Datetime, Tagname, Value and Quelity datail the name of the columms.
'close the connection
If cn.State = 1 Then
    cn.Close
End If

End Sub


I hope it will help you.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Syntax in VBA? Bill_L Excel VBA 0 September 11th, 2008 08:47 AM
Excel VBA & SQL LouNeate Excel VBA 2 April 5th, 2007 01:28 PM
SQL Date query in Excel VBA lanewalk Excel VBA 2 September 27th, 2006 02:04 AM
Which Book for VBA/Access/SQL/Excel? rmg VB Databases Basics 0 July 29th, 2004 03:19 PM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.