Hi All
as is always the way, i'm going back through the early vba code i wrote creating my database and applying the knowledge and experience i have gained since writing said bit of code.
I have been converting a lot of:
but i have hit a bit of code and am not sure how i'd go about changing it:
so basically i want to design an update query that only updates fields that have been selected to be updated by the user and i'm not sure how to build that.
if say cboType is not set the records selected would not have the data altered if there was data already there, if it was selected then the data is written to the field of the record
hope that makes sense
as always any help/direction will be gratefully received even if it is that what i want to do is actually better done like the above code does, hence the subject
kind regards
Glen
as is always the way, i'm going back through the early vba code i wrote creating my database and applying the knowledge and experience i have gained since writing said bit of code.
I have been converting a lot of:
- Get recordset
- loop through recordset 1 record at a time
- if record matches a certain criteria
- update set of fields of record
- end if
- if record matches a certain criteria
- end loop
but i have hit a bit of code and am not sure how i'd go about changing it:
Code:
Private Sub btnUpdateSelected_Click()
If IsNull(Me.txtSelected) Or Me.txtSelected = "" Or Me.txtSelected = "," Then
Me.txtInfoMessages = "No records selected"
Exit Sub
End If
Dim rs As DAO.Recordset
Set rs = Form.Recordset
With rs
.MoveFirst
Do While Not .EOF
If Me.txtSelected Like "*," & !id & ",*" Then
.Edit
If Not (IsNull(Me.txtReferenceNumber)) And Me.txtReferenceNumber <> "" Then !reference = Me.txtReferenceNumber
If Not (IsNull(Me.cboType)) And Me.cboType <> "" Then !type_id = Me.cboType
If Not (IsNull(Me.cboSubType)) And Me.cboSubType <> "" Then !subtype_id = Me.cboSubType
If Not (IsNull(Me.cboFromCompany)) And Me.cboFromCompany <> "" Then !from_id = Me.cboFromCompany
If Not (IsNull(Me.cboToCompany)) And Me.cboToCompany <> "" Then !to_id = Me.cboToCompany
If Not (IsNull(Me.cboCurrency)) And Me.cboCurrency <> "" Then !currency_id = Me.cboCurrency
If Not (IsNull(Me.cboStatus)) And Me.cboStatus <> "" Then !status_id = Me.cboStatus
If Not (IsNull(Me.txtInvoiceDate)) And Me.txtInvoiceDate <> "" Then !date_of_INVorCN = Me.txtInvoiceDate
.Update
End If
.MoveNext
Loop
.MoveFirst
End With
Set rs = Nothing
End Sub
so basically i want to design an update query that only updates fields that have been selected to be updated by the user and i'm not sure how to build that.
if say cboType is not set the records selected would not have the data altered if there was data already there, if it was selected then the data is written to the field of the record
hope that makes sense
as always any help/direction will be gratefully received even if it is that what i want to do is actually better done like the above code does, hence the subject
kind regards
Glen