- Joined
- Sep 9, 2002
- Messages
- 5,657
Edit: nevermind - I'm dumb... no help needed. If anyone was interested, yes openning the connection and recordset was enough and omitting my UID and password for a local server with win authentication was the right thing to do. The error was an alternate way of setting up the Students database but apparently because I operate on the connection and not the recordset, what I had before the error was all we need and the right way to do it.
Orig post: If anyone can give me a little tip here I would sure appreciate it. Most of this code is really a quick read through - beginner stuff (2nd half is record navigation). My problem is at the top just in the connection so this isn't one of those here's gobs and gobs of code where's my problem posts. I bolded out the problem. I can work on little stuff... just gotta get the connection going. This is an example I adapted a bit for my own use but even if I copy the code verbatim like the example with copy - paste I will get the error. I'm confused it seems we've defined the connection and recordset, which I thought was enough, then we have the problem line. I am not used to working with workspaces before so I dunno what gives here.
This is all just practice stuff. I thought it OK not to proclaim a UID or password in my X string variable as it's a local server with windows authentication. The example sited having UID=sa and password blank but my DSN is not setup like that. Trying to set my DSN to sa/blank errors as I set it up with win authentication only. "Connection failed, non trusted connection"
_______________________________________________________________________
Dim wrkODBC As Workspace
Dim StudentDatabaseConnection As Connection
Dim StudentDatabase As Recordset
Private Sub Form_Load()
Dim X As String
X = "ODBC;database=sample;DSN=Students;"
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "", "", dbUseODBC)
Set StudentDatabaseConnection = wrkODBC.OpenConnection("Students", , False, X)
Set StudentDatabase = StudentDatabaseConnection.OpenRecordset("Students", dbOpenDynamic)
Rem Errors - says "expecting =" or simply "syntax error"
wrkODBC.OpenConnection("Students", , False, X).OpenRecordset("Students", dbOpenDynamic)
End Sub
Private Sub cmdSave_Click()
Dim SQLStmt As String
SQLStmt = "INSERT INTO Students (SSN, FirstName, LastName, Major, GradDate) "
SQLStmt = SQLStmt & "VALUES ('" & txtSSN.Text & "', '" & txtLastName.Text & "', '"
SQLStmt = SQLStmt & txtFirstName.Text & "', '" & txtMajor.Text & "', '" & txtGradDate.Text & "')"
StudentDatabaseConnection.Execute SQLStmt
End Sub
Private Sub cmdFirst_Click()
StudentDatabase.MoveFirst
End Sub
Private Sub cmdLast_Click()
StudentDatabase.MoveLast
End Sub
Private Sub cmdNext_Click()
StudentDatabase.MoveNext
End Sub
Private Sub cmdPrev_Click()
StudentDatabase.MovePrevious
End Sub
Private Sub cmdExit_Click()
StudentDatabase.Close
StudentDatabaseConnection.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
StudentDatabase.Close
StudentDatabaseConnection.Close
End Sub
_______________________________________________________
Orig post: If anyone can give me a little tip here I would sure appreciate it. Most of this code is really a quick read through - beginner stuff (2nd half is record navigation). My problem is at the top just in the connection so this isn't one of those here's gobs and gobs of code where's my problem posts. I bolded out the problem. I can work on little stuff... just gotta get the connection going. This is an example I adapted a bit for my own use but even if I copy the code verbatim like the example with copy - paste I will get the error. I'm confused it seems we've defined the connection and recordset, which I thought was enough, then we have the problem line. I am not used to working with workspaces before so I dunno what gives here.
This is all just practice stuff. I thought it OK not to proclaim a UID or password in my X string variable as it's a local server with windows authentication. The example sited having UID=sa and password blank but my DSN is not setup like that. Trying to set my DSN to sa/blank errors as I set it up with win authentication only. "Connection failed, non trusted connection"
_______________________________________________________________________
Dim wrkODBC As Workspace
Dim StudentDatabaseConnection As Connection
Dim StudentDatabase As Recordset
Private Sub Form_Load()
Dim X As String
X = "ODBC;database=sample;DSN=Students;"
Set wrkODBC = CreateWorkspace("ODBCWorkspace", "", "", dbUseODBC)
Set StudentDatabaseConnection = wrkODBC.OpenConnection("Students", , False, X)
Set StudentDatabase = StudentDatabaseConnection.OpenRecordset("Students", dbOpenDynamic)
Rem Errors - says "expecting =" or simply "syntax error"
wrkODBC.OpenConnection("Students", , False, X).OpenRecordset("Students", dbOpenDynamic)
End Sub
Private Sub cmdSave_Click()
Dim SQLStmt As String
SQLStmt = "INSERT INTO Students (SSN, FirstName, LastName, Major, GradDate) "
SQLStmt = SQLStmt & "VALUES ('" & txtSSN.Text & "', '" & txtLastName.Text & "', '"
SQLStmt = SQLStmt & txtFirstName.Text & "', '" & txtMajor.Text & "', '" & txtGradDate.Text & "')"
StudentDatabaseConnection.Execute SQLStmt
End Sub
Private Sub cmdFirst_Click()
StudentDatabase.MoveFirst
End Sub
Private Sub cmdLast_Click()
StudentDatabase.MoveLast
End Sub
Private Sub cmdNext_Click()
StudentDatabase.MoveNext
End Sub
Private Sub cmdPrev_Click()
StudentDatabase.MovePrevious
End Sub
Private Sub cmdExit_Click()
StudentDatabase.Close
StudentDatabaseConnection.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
StudentDatabase.Close
StudentDatabaseConnection.Close
End Sub
_______________________________________________________