|
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
|
|
|
October 4th, 2004, 05:32 AM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
October 5th, 2004, 03:11 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What do you mean about: first 3-5 character or only name?
Characters: 3, 4 and 5?
|
October 5th, 2004, 10:11 AM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|
October 5th, 2004, 11:14 AM
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
October 6th, 2004, 04:15 AM
|
Registered User
|
|
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
|
|