Hi all,
I have created a simple feedback form in Access...but am having a couple of problems. As a complete Access/VBA newbie I'm not sure what is going wrong....
There is a cbo for 'Category' - and if a category is not selected I would like a msgbox to pop up prompting the user to select one.
For some reason this is not working with the code below....can anyone offer a suggestion as to why?
Private Sub cmd_Submit_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= C:\..............;"
rs.Open "tblFeedback", , adOpenKeyset, adLockOptimistic, adCmdTable
If Me.txt_name.Visible = True Then
If Me.cbo_category.Value = Null Then
Msgbox "Please select a category", vbokonly, "Category not selected"
Me.cbo_category.SetFocus
With rs
.AddNew
.Fields("Category") = Me.cbo_category.Value
.Fields("Feedback") = Me.txt_feedback.Value
.Fields("Name") = Me.txt_name.Value
.Update
End With
End If
If Me.txt_name.Visible = False Then
With rs
.AddNew
.Fields("Category") = Me.cbo_category.Value
.Fields("Feedback") = Me.txt_feedback.Value
.Fields("Name") = "Anonymous"
.Update
End With
End If
End If
rs.Close
Set rs = Nothing
Me.cbo_category.Value = Null
Me.txt_feedback.Value = Null
Me.txt_name.Value = Null
Me.txt_name.Visible = True
Me.lbl_or.Visible = True
MsgBox "Thank you. Your feedback has been submitted", vbOKOnly, "Feedback Received"
End Sub
I have created a simple feedback form in Access...but am having a couple of problems. As a complete Access/VBA newbie I'm not sure what is going wrong....
There is a cbo for 'Category' - and if a category is not selected I would like a msgbox to pop up prompting the user to select one.
For some reason this is not working with the code below....can anyone offer a suggestion as to why?
Private Sub cmd_Submit_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= C:\..............;"
rs.Open "tblFeedback", , adOpenKeyset, adLockOptimistic, adCmdTable
If Me.txt_name.Visible = True Then
If Me.cbo_category.Value = Null Then
Msgbox "Please select a category", vbokonly, "Category not selected"
Me.cbo_category.SetFocus
With rs
.AddNew
.Fields("Category") = Me.cbo_category.Value
.Fields("Feedback") = Me.txt_feedback.Value
.Fields("Name") = Me.txt_name.Value
.Update
End With
End If
If Me.txt_name.Visible = False Then
With rs
.AddNew
.Fields("Category") = Me.cbo_category.Value
.Fields("Feedback") = Me.txt_feedback.Value
.Fields("Name") = "Anonymous"
.Update
End With
End If
End If
rs.Close
Set rs = Nothing
Me.cbo_category.Value = Null
Me.txt_feedback.Value = Null
Me.txt_name.Value = Null
Me.txt_name.Visible = True
Me.lbl_or.Visible = True
MsgBox "Thank you. Your feedback has been submitted", vbOKOnly, "Feedback Received"
End Sub