Hi all,
I have tried to find the solution for this on the site...not sure if I am searching for the right terms though as I cannot seem to locate what I need. I was hoping someone could help me out.
I am trying to select a record where the the field 'ID' equals 'Me.txtans.Value' and update other fields in that record.
Here's what I have -
Private Sub cmdSubmit_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= G:\...\complaints.mdb;"
rs.Open "tblEnquiries", , adOpenKeyset, adLockOptimistic, adCmdTable
With rs
If .Fields("ID") = Me.txtAns.Value
.Fields("Date_Received") = Date
.Fields("Time_Received") = Time
.Fields("Type") = Me.cboType.Value
.Fields("Category") = Me.cboCategory.Value
.Fields("Description") = Me.txtDescr.Value
.Fields("Customer_Outcome") = Me.txtCusOut.Value
.Update
End If
End With
rs.Close
Set rs = Nothing
End Sub
I am absolutely certain my code to select the record is incorrect...but I'm really not sure what I should be using. I tried to use a SQL 'SELECT' statement - but it did not like my syntax - I kept getting a 'Case' error.
Could anyone advise what the correct way to select a record from a table is please?
Thank you
Rob
I have tried to find the solution for this on the site...not sure if I am searching for the right terms though as I cannot seem to locate what I need. I was hoping someone could help me out.
I am trying to select a record where the the field 'ID' equals 'Me.txtans.Value' and update other fields in that record.
Here's what I have -
Private Sub cmdSubmit_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= G:\...\complaints.mdb;"
rs.Open "tblEnquiries", , adOpenKeyset, adLockOptimistic, adCmdTable
With rs
If .Fields("ID") = Me.txtAns.Value
.Fields("Date_Received") = Date
.Fields("Time_Received") = Time
.Fields("Type") = Me.cboType.Value
.Fields("Category") = Me.cboCategory.Value
.Fields("Description") = Me.txtDescr.Value
.Fields("Customer_Outcome") = Me.txtCusOut.Value
.Update
End If
End With
rs.Close
Set rs = Nothing
End Sub
I am absolutely certain my code to select the record is incorrect...but I'm really not sure what I should be using. I tried to use a SQL 'SELECT' statement - but it did not like my syntax - I kept getting a 'Case' error.
Could anyone advise what the correct way to select a record from a table is please?
Thank you
Rob