0

I have a userform called Attendance that has two listboxes on it. One called Seated, one called NotSeated.

In a SQL column everyone starts the day off as '1'. If someone is here today they get marked as '2', if they aren't they get marked as a '3' or a '4'.

I have a reset button that I want to have reset them to '1' when pressed. What I need to be able to do is to change my UPDATE query based on which listbox the user has currently highlighted. Here is what I have so far, but it's not working.

Sub resetagent()
database_connect
Dim AttendRecord As New ADODB.Recordset
Dim Cm As ADODB.Command
If appconn.State = 0 Then
Call database_connect
End If
Set Cm = New ADODB.Command
With Cm
    .ActiveConnection = appconn
    If attendance.Seated.value <> "" Then
    .CommandText = "UPDATE [Attendance] SET [Seated] = '1' WHERE [Agentname]= '" & attendance.Seated.value & "'"
    ElseIf attendance.NotSeated.value <> "" Then
    .CommandText = "UPDATE [Attendance] SET [Seated] = '1' WHERE [Agentname]= '" & attendance.NotSeated.value & "'"
    .CommandType = adCmdText
    .Execute
End If
End With
Set AttendRecord = Nothing
database_Disconnect
End Sub
2
  • 2
    It looks like the last End If is in the wrong spot. Move it up 2 lines, just after the second CommandText. Commented Aug 2, 2018 at 20:00
  • That fixed it. I can't believe I missed that. Commented Aug 2, 2018 at 20:12

1 Answer 1

1

Your .Execute is sitting inside your if statement and can only run if you are in the Else portion of the statement. Move the End ifstatement up 2 lines.

Also if both list boxes are not blank (i.e. one is a '1' and the other is a '3') then it would not match either of the If statement conditions and do nothing here.

One you move the End If line, it would execute whatever the button's defaulted CommandText is.

Sign up to request clarification or add additional context in comments.

1 Comment

That fixed it! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.