Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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
 
Old December 22nd, 2004, 01:05 PM
Authorized User
 
Join Date: Dec 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default problems connecting to a database

hi this is my first post i hope you can help.

i need to connect to a access accounts database to change the customers records but to do this i want to have a form that allows you to type in the DataSettings i did connect to the database using a clas modual with the code

Const Userid As String = "SA"
Const UserName As String = "sa"
Const Password As String = "a1471956"
Const DatabaseName As String = "a241b"
Const ServerName As String = "TECH01\TECH01"


Public Sub DataSetting(ObjectName As Object)

    With ObjectName
        .DataSetting.Userid = Userid
        .DataSetting.UserName = UserName
        .DataSetting.Password = Password
        .DataSetting.DatabaseName = DatabaseName
        .DataSetting.ServerName = ServerName
    End With

End Sub

Public Function ADOConnString() As String

    ADOConnString = "Provider=sqloledb;Data Source=" & ServerName & ";Initial Catalog=" & DatabaseName & ";User Id=" & Userid & ";Password=" & Password & "; "

End Function

i used this in a form to enter the customers details with the code
Private ObjCust As Dimensions.Customer
Private DBConn As New DimensionsDBConnection


Public Sub btnSubmit_click()
On Error GoTo Err_Cust
    Set ObjCust = New Dimensions.Customer
    DBConn.DataSetting ObjCust

        With ObjCust
            .Create
            .Record.Code = "bob"
            .Record.Name = "mattjobb"
            .Record.AccountAddress = "this place"
            .Record.Town = "syresham"
            .Record.County = "northants"
            .Record.Postcode = "nn13 5hs"
            .Record.Phone = "01280850308"
            .Record.ContactTitle = "mr"
            .Record.ContactSurname = "bob"
            .Record.ContactFirstName = "matt"
            .Save
        End With
    MsgBox "Contact Added Succesfully", vbOKOnly

Exit Sub
Err_Cust:
    MsgBox Err.Description

End Sub


this all worked but thats not the problem when i tried to change the first formula to read the text boxes on a form i found i couldnt so i changed the form to this

Dim Userid As String
Dim UserName As String
Dim Password As String
Dim DatabaseName As String
Dim ServerName As String

Private Function setstring()
Userid = txtUserid.Text
UserName = txtUsername.Text
Password = txtPassword.Text
DatabaseName = txtDBname.Text
ServerName = txtSVRname.Text
End Function

Private Function Setconst()
Const Userid1 As String = Userid
Const UserName1 As String = UserName
Const Password1 As String = Password
Const DatabaseName1 As String = DatabaseName
Const ServerName1 As String = ServerName

End Function

Public Sub DataSetting(ObjectName As Object)

    With ObjectName
        .DataSetting.Userid = Userid1
        .DataSetting.UserName = UserName1
        .DataSetting.Password = Password1
        .DataSetting.DatabaseName = DatabaseName1
        .DataSetting.ServerName = ServerName1
    End With

End Sub

Public Function ADOConnString() As String

    ADOConnString = "Provider=sqloledb;Data Source=" & ServerName1 & ";Initial Catalog=" & DatabaseName1 & ";User Id=" & Userid1 & ";Password=" & Password1 & "; "

End Function

Public Sub btnConnect_Click()

Menu.Show


End Sub

this came up with the error msg that i was not supplying a data base name


i am sorry this is so long winded but i like you to know the whole story so the help you could give me is how to either get a constan to read a test box on a form and then to get a constent on a class modual to read a constatnt or dim variable on a form or just how to do this better.

thank you very much for your time

Regards

Matthew Allee

I.T Consultant
R Charles Associates





Similar Threads
Thread Thread Starter Forum Replies Last Post
problems connecting to SQL Server KW C# 2005 0 August 31st, 2007 05:59 PM
Having problems connecting VB to SQL schow ASP.NET 2.0 Basics 0 March 28th, 2007 11:22 PM
Problems with connecting tumb SQL Server 2000 1 December 22nd, 2005 04:16 PM
problems connecting to database jula MySQL 0 December 3rd, 2004 09:26 PM
Problems connecting SQL Server from VB 6 mikko SQL Server 2000 6 February 12th, 2004 05:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.