Hi All,
I can trying to insert a record from a form using a button's onclick event but have run into some problems.
Problem 1:
When the onclick event is fired, I am prompted with an error message stating that the access database file can not be found in my documents. How do I over come that problem?
Problem 2:
It's not really a problem but more like a I have forgotten the syntax. When creating the insert syntax, I can't remember how to specify the textboxes as values. You can see from my code below.
Code:Private Sub btnCreateEmp_Click() Dim cn As ADODB.Connection Dim cmd As ADODB.Command Dim sSQL As String Dim strConString As String Set cn = New ADODB.Connection Set cmd = New ADODB.Command strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Client Details.MDB; Persist Security Info=False;Mode=Read|Write" cn.ConnectionString = strConString cn.Open sSQL = "INSERT INTO EmployeeDetails ([FirstName]) VALUES ('Me!FNAME')" With cmd .ActiveConnection = cn .CommandText = sSQL .CommandType = adCmdUnknown .Execute End With Set cmd = Nothing cn.Close Set cn = Nothing End Sub




Reply With Quote