Hello,
I have 6 combo boxes on a form and want to construct a insert statement from the values on the boxes, via VBA. This works fine as long as all the boxes have a value selected, but if some boxes are empty I understandably get a error.
I would like a elegant way to handle nulls where no value was selected in the combo box.
Here is the code:
Code:
Private Sub cmd_submit_Click()
' *** A FUCNTION ON CLICK TO UPDATE THE MTG TABLE WITH PERSONS PRESENT - ON SUBMIT
Dim strSQL As String
Dim rs As Recordset
Dim db As DAO.Database
Dim contr As Control
Set db = CurrentDb
' *** GET THE ID NUMBERS FROM THE HIDDEN COLUMS IN DROPDOWN LIST
str_facilitator_ID = Me.combo_facilitator.Column(1)
str_admin_ID = Me.combo_admin.Column(1)
str_HB_ID = Me.combo_HB.Column(1)
str_YF_ID = Me.combo_YF.Column(1)
str_corr_ID = Me.combo_corr.Column(1)
str_port_ID = Me.combo_port.Column(1)
' CONSTRUCT A STRING OF ID NUMBERS TO PUT INTO THE INSERT SQL STATEMENT
str_IDs = str_corr_ID & "," & str_HB_ID & "," & str_YF_ID & "," & str_facilitator_ID & "," & str_admin_ID & "," & str_port_ID
' *** INSERT THE ID VALUES OF PEOPLE PRESENT FROM THE FORM AND INSERT INTO MTG TABLE
strSQL = "INSERT INTO tbl_mtg (corr_person_ID, HB_person_ID, yf_person_ID, facilitator_ID, admin_ID, port_ID, Comments) VALUES (" & str_IDs & ",'" & txt_comments & "');"
Debug.Print (strSQL)
' *** EXECUTE THE UPDATE
db.Execute strSQL, dbFailOnError
' *** TIDY UP
strSQL = ""
db.Close
Set db = Nothing
End Sub
-Al