|
-
Sep 20th, 2012, 09:40 AM
#1
Thread Starter
Member
Need help with Excel in VB
I have in excel file, which contains in button. So what Im trying to to do is, whenever I click the button. I wont to be able to send the time I click the button to a sql table. If someone can help. Please I need it.
-
Sep 20th, 2012, 10:18 AM
#2
Re: Need help with Excel in VB
That means you need to have an ADO Connection Object and then execute a SQL Insert or Update statement on your database using said connection. There are many good tutorials and samples for how to work with data using ADO both of this site and throughout the net. A quick search would be in order.
-
Sep 20th, 2012, 11:44 AM
#3
Re: Need help with Excel in VB
Excel VBA question moved to Office Development
-
Sep 20th, 2012, 03:02 PM
#4
Thread Starter
Member
Re: Need help with Excel in VB
I have in excel file, which contains in macro button. So what Im trying to to do is, whenever I click the button. I wont to be able to send the time I click the button to a sql table. If someone can help. If anyone know how to do this thru macro. Please point me in that direction.
-
Sep 20th, 2012, 03:57 PM
#5
Re: Need help with Excel in VB
I wont to be able to send the time I click the button to a sql table.
what type of table?
what database?
what other code do you have for working with the database?
search in the database forum for insert or add to a recordset
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 21st, 2012, 10:23 AM
#6
Thread Starter
Member
Re: Need help with Excel in VB
I tried in code on the marcos in excel, but it still not work propely. I wont the button to send a something to the table I have one sql. That something is like a example; whatever time i hit the marco button, I wont it to appear in the sql table when i click on the button. the code im working with is below, but dont know if im doing right or not.
Sub TestImportUsingADO()
Dim conString As String
conString = "Server=10.53.252.221;UID=phasqladmin;PWD=i82dothis;Database=phabsproduction;"
Dim query As String
query = "insert into [Table_1] ([Time Submited])values ('9-20-2012')"
Dim target As Range
Set target = ThisWorkbook.Sheets(2).Cells(3, 2)
target.CurrentRegion.Clear
Select Case ImportSQLtoRange(conString, query, target)
Case 1
MsgBox "Import database data error", vbCritical
Case Else
End Select
-
Sep 21st, 2012, 01:53 PM
#7
Re: Need help with Excel in VB
What is the code in the ImportSQLtoRange function?
-
Sep 21st, 2012, 02:20 PM
#8
Thread Starter
Member
Re: Need help with Excel in VB
I don't have that, having problems
-
Sep 21st, 2012, 03:51 PM
#9
Re: Need help with Excel in VB
the code you posted implies the existance of a function named ImportSQLtoRange() which accepts 3 parameters and returns a result that can be a 1
The code you have posted doesn't really do anything other than set some values for use in this function so ....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|