Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 30

Thread: Store in DataBase

  1. #1
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location

    Store in DataBase

    Hi to everyone
    I'd like to ask how can i will stored some data in a database? How can i doit this?

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    Option Explicit
    Private Sub btnCancel_Click()
        Unload Me
    End Sub
    
    
    Private Sub btnOK_Click()
        Dim ws As Worksheet
        Set ws = ActiveSheet
        Dim newRow As Long
        
        newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
        
        'The next two lines can be expanded as many times as needed for all the entry fields in your project
        
        ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
        ws.Cells(newRow, 2).Value = Me.txtSurname.Value
        
    End Sub
    Sub CommandButton1_Click()
        Selection.EntireRow.Delete
    End Sub
    Attached find the workbook. This is the basic setup for creating a database. You can add as many TextBox fields as required and amend the code as required.
    Attached Files Attached Files

  3. #3
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Hi Logit .Thank you for your answer but i don't understant , where is the name of the DB and the fields, and how to recall the entries?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Your question needs a lot more detail.

    What do you mean by a database? SQL Server, Access, Excel workbook, text file?

    What do you mean by store data? Insert new data, update existing data, delete data?

    Where will the data originate from? Will it be a text file, will users input to an Excel worksheet, will they input to a userform?

    How will you control the application?

    Etc. Etc. Etc.

    and what can you do yourself?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Hi xld .To answer your questions
    1. SQL Server . Where i will find this. Is it with Excell? . How to connect it?
    2. Insert,update,delete ,....
    3. I will manage all these from a userform
    4. The app isn't an Excell but a SolidWorks app , but they have the same VBA language
    Regards

  6. #6
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    What level of experience do you presently have creating / editing / manipulating data into a "database" ?

    Your current level of understanding would be an indicator of what material to supply to you for review. Also,
    please provide answers to xld's posting as those answers would also provide guidance how to respond to your request.

    Thanks.

  7. #7
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    I used to programming in DELPHI with SQL DataBase so my experience to a DB is good enough(for the DELPHI). Now i am furniture designer and i use the SolidWorks for that . I am creating some macros in VBA language (i am new in VBA language) so i have some blanks in VBA , how to connenct with the SQL server , how to manipulate the data etc

  8. #8
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Great ! There are volunteers here and other forums that should be able to assist you with your needs. Regretfully, I do not know anything about SQL.

    Best wishes.

  9. #9
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    As this is an Excel forum, most people here will not be familiar with SolidWorks therefore, if I were you, I'd post this question in a more suitable forum.
    Semper in excretia sumus; solum profundum variat.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    SQL is fine, loads of us here know it. What we might not know is SolidWorks, how accessible it is, what the connection strings are, what the table structures are.

    But the question you ask is big, so I think we need to take it in small steps. We cannot possibly build the whole app from what you have given us, so best to post several different questions on different aspects.

    What is the first ting you want to do in this app (keep it manageable)?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Hi to all .Thank you all for your answers ,but i asked how can i connect from vba environment to a SQL Database , if its possible.
    Anyway if its too difficult i will pick another way

  12. #12
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Sub WriteToDB
        Dim cn As New ADODB.Connection
        #If Win64 Then
        cn.Open "Provider=MSDASQL;DRIVER={mysql odbc 5.2 unicode driver}" _
        & ";SERVER=localhost" _
        & ";PORT=3306" _
        & ";DATABASE=SomeDBase" _
        & ";UID=UserName" _
        & ";PWD=Password"
        #Else
        cn.Open "DRIVER={MySQL ODBC 3.51 Driver}" _
        & ";SERVER=localhost" _
        & ";PORT=3306" _
        & ";DATABASE=SomeDBase" _
        & ";UID=UserName" _
        & ";PWD=Password"
        #End If
        cn.Execute "UPDATE ked_festival_ticket_holders_attendance_" & DATA.Cells(13, 1) & " SET " & Evnt & " = '" & yn & "' WHERE Ticket_No = " & Tkt
        cn.Close
        Set cn = Nothing
    End Sub
    This checks if you are using 64 or 32bit Excel then connects to an SQL database.
    Semper in excretia sumus; solum profundum variat.

  13. #13
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    Hi I copied the code above but i have a compile error " User-defined type not defined" on "Dim cn As New ADODB.Connection" .

  14. #14
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You probably haven't set the Active X reference in the VBE window.
    Semper in excretia sumus; solum profundum variat.

  15. #15
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    You mean "Microsoft ActiveX... I have a lot of these .Look scr(56)
    Attached Images Attached Images

  16. #16
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Which ones have you tried? I would think the latest one. If you want to work with recordsets too then you may need that reference as well.

    I suggest you do some Googling, there are numerous posts on connections and connection strings.
    Semper in excretia sumus; solum profundum variat.

  17. #17
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    I have checked the latest but i have some issues . Propably i must install the SQLSERVER 2014 . I don't know but i have all the package on my PC but it's need to install it

  18. #18
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Have you got an SQL database to test with?
    Semper in excretia sumus; solum profundum variat.

  19. #19
    VBAX Regular
    Joined
    Aug 2019
    Posts
    54
    Location
    No i haven't . I am looking for the installation but i can't find any. Propably i don't have the SQLServer . Anyway i will looking for that and i will try again .Anyway Thank you for all

  20. #20
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Before you do that, how many records do you want to store? 100's, 1,000's or 10,000+ records? You could do 1,000's in Excel without a problem.
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •