Dim EN As rdoEnvironment
Dim CN As rdoConnection Dim CL As rdoColumn Public mySQL As String Public Sub RegisterDataSource() 'What this sub does is registers a datasource in the 'ODBC object in Control Panel.This is so the RDO can 'Talk to the SQL server. On Error Goto Handle Dim strAttribs As String Dim x 'This will build a string containing the attributes 'Description - Just a general desc. of the server 'OemToAnsi - Just keep it on NO 'Server - The name of the server your connecting to 'Network - Type of connection. DBMSSOCN = TCP/IP. 'The only other one you should use would be Named 'Pipes, but only if your on a Lan Database - Name 'of the database to connect to strAttribs = "Description=" _ & "Description of server" _ & vbCrLf & "OemToAnsi=No" _ & vbCrLf & "SERVER=Server_Name" _ & vbCrLf & "Network=DBMSSOCN" _ & vbCrLf & "Database=database_name" _ & vbCrLf & "Address=255.255.255.255" 'Create new registered DSN.Leave this rdoEngine.rdoRegisterDataSource "Table_name", _ "SQL Server", True, strAttribs 'only thing you should change in this would 'be the Table_Name, and Read Only Exit Sub Handle: MsgBox Err.Number & vbCrLf & Err.Description End Sub Private Sub Form_Load() 'We will set up everything we need here Dim max As Long 'Set the environment for the rdo engine Set EN = rdoEngine.rdoEnvironments(0) 'Define the cursor driver EN.CursorDriver = rdUseOdbc 'Open a connection to the SQL database Set CN = EN.OpenConnection("Table_Name", dbDriverNoPrompt, _ False, "driver=SQLServer; database=Database_Name; _ uid=User_ID; pwd=PASSWORD;") 'Set the SQL command - For now, we will select all of the fields 'from the record if the UserID field is equal to 'Dustin' mySQL = "SELECT * FROM Users WHERE UserID='Dustin'" 'Users = The table name 'This will query the database with the SQL command you gave above. Set RS = CN.OpenResultset(mySQL, rdOpenKeyset, rdConcurReadOnly, _ rdAsyncEnable + rdExecDirect) 'this will get the total # of records itfound. max = CInt(CN.LastQueryResults.RowCount) 'The results are stored in the CL variable. We will have to set them Set CL = RS.rdoColumns(0) text1.Text = CL.Value Set CL = RS.rdoColumns(1) text2.Text = CL.Value CN.Close 'Close connection With DB EN.Close 'Close the environment Exit Sub 'gotta Do this so it wont go streight through and Error out 'if there was no err. Err: If Err.Number = 40006 Then 'this will popup if nothing was found MsgBox "No records Found" Else MsgBox Err.Description End If End Sub Inputs: refrence to Microsoft Remote Data Object 2.0 refrence To ODBC Driver & data source name functions |