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
|