datacontrol
Registered User.
- Local time
- Today, 21:13
- Joined
- Jul 16, 2003
- Messages
- 142
Hello all....I have come a long way in learning VBA with the help of this forum. As seen below, I have a large amount of else if's. 45 to be exact. Is there any way to clean this up? It works great, but I am just wondering if it could be simplified.
How would I store the sql command INSERT INTO so that it could be referenced bay a variable name?
ElseIf (Me!task) = 1 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your CYCLE END data has been saved."
Exit Sub
ElseIf (Me!task) = 2 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your OUTSIDE LISTS data has been saved."
Exit Sub
ElseIf (Me!task) = 3 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your DISCONTINUED OR TRANSFERRED PUB CONVERSION FILES data has been saved."
Exit Sub......................
.............................
How would I store the sql command INSERT INTO so that it could be referenced bay a variable name?
ElseIf (Me!task) = 1 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your CYCLE END data has been saved."
Exit Sub
ElseIf (Me!task) = 2 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your OUTSIDE LISTS data has been saved."
Exit Sub
ElseIf (Me!task) = 3 Then
DoCmd.RunSQL "INSERT INTO tbldst(dst_date, dst_user, dst_num_req_rec, dst_num_req_pro, dst_time, dst_task_id) VALUES ('" & Me.date & "','" & Me.user & "','" & Me.rr & "','" & Me.rc & "','" & Me.time & "','" & Me.task & "')"
DoCmd.Close
MsgBox "Your DISCONTINUED OR TRANSFERRED PUB CONVERSION FILES data has been saved."
Exit Sub......................
.............................