Quite awhile back, I designed something similar. It wasn't a single string, but rather a series of IF statements that build the sql string, something like the following. I didn't try to guess which fields of yours are required and which are not.
When the above is all done, you should be able to modify your main sql statement something like:Code:Dim sFields As String, sValues As String ' first include all required fields in the sFields string sFields = "CR_Number, Procedure_Name" ' add others as needed ' then the Values for the required fields sValues = "'" & frmMain.txtCRNumber & "', '" & frmMain.txtProcedure.Text & "'" ' now handle optional fields and values sFields = sFields & ", Unit_Admit_Datetime" If dtUnitAdmitDate<>0# Then sValues = sValues & ", #" & dtUnitAdmitDate & "#" Else sValues = sValues & ", " & Null End If ' P.S. Don't remember, if inserting a new record must all fields be included in the field list? ' If not, just don't add it and it should be populated with its default new record values which may be Null ' handle other optional fields/values
The above sample was "air code" therefore, typos may existCode:"Insert Into Master_Review(" & sFields & ") VALUES (" & sValues & ")"




Reply With Quote