Results 1 to 9 of 9

Thread: Need help with Excel in VB

  1. #1
    Member
    Join Date
    Jun 12
    Posts
    41

    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 12
    Location
    West Virginia
    Posts
    4,957

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,283

    Re: Need help with Excel in VB

    Excel VBA question moved to Office Development
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4
    Member
    Join Date
    Jun 12
    Posts
    41

    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 04
    Posts
    18,532

    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
    Member
    Join Date
    Jun 12
    Posts
    41

    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 12
    Location
    West Virginia
    Posts
    4,957

    Re: Need help with Excel in VB

    What is the code in the ImportSQLtoRange function?

  8. #8
    Member
    Join Date
    Jun 12
    Posts
    41

    Re: Need help with Excel in VB

    I don't have that, having problems

  9. #9
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    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
  •