Results 1 to 9 of 9

Thread: Need help with Excel in VB

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    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.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help with Excel in VB

    Excel VBA question moved to Office Development

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    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.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    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

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Need help with Excel in VB

    What is the code in the ImportSQLtoRange function?

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    Re: Need help with Excel in VB

    I don't have that, having problems

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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
  •  



Click Here to Expand Forum to Full Width