Jadz
2010-11-25 22:44:21 UTC
Private Sub Form_Load()
'Declare the variable
Dim cnnNorthwind As ADODB.Connection
'Define a new Recordset
Dim rsEmployees As ADODB.Recordset
Dim strFName As String
Dim strLName As String
Dim datBirthDate As Date
'Open a connection using a DSN
Set cnnNorthwind = New ADODB.Connection
'Define the connection string as the DSN Northwind
cnnNorthwind.ConnectionString = "DSN= Northwind"
MsgBox "The Connection State is " & cnnNorthwind.State
cnnNorthwind.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Program Files\Microsoft Visual Studio\VB98\NWIND.mdb"
MsgBox "The Connection State is " & cnnNorthwind.State
'Execute the command on the connection, creating a Recordset
strName = InputBox("Please enter your First Name:")
strName = InputBox("Please enter your Last Name:")
strName = InputBox("Please enter your BirthDate:")
cnnNorthwind.Execute ("Insert into Employees (FirstName, LastName, Title, BirthDate) Values (' " & strFName & ' ", & strLName & ' ", 'Sales Representative', " & datBirthDate&")") <<<<<<<<<<<<<<<<<<<<<< This is my main Problem
Set rsEmployees = New ADODB.Recordset
Set rsEmployees = cnnNorthwind.Execute("Select FirstName, LastName FROM Employees WHERE Title = 'Sales Representative'", adCmdText)
'List all the names on the form
Do While rsEmployees.EOF <> True
lblNames.Caption = lblNames.Caption & vbCrLf & "" & _
rsEmployees.Fields("FirstName") & "" & _
rsEmployees.Fields("LastName")
rsEmployees.MoveNext
Loop
'Close the connection
cnnNorthwind.Close
MsgBox "The Connection State is " & cnnNorthwind.State
End Sub