Link to home
Start Free TrialLog in
Avatar of J G
J G

asked on

update query

Ok,

I have 5 fields I want to update if a checkbox is checked. Not sure if I should actually update the records in VBA or if I should use a query that is invoked in vba   What would be the better practice?  If in VBA what would the syntax be?

basically the update query would be like this:

If I do it all in VBA:

if check box is checked

update field 1 where tbl_store_Item.plu=tble_Item.PLU

If I use a query vba would be:

if check box is checked

run field1.query
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are updating the currently active record, it is better to simply populate the fields directly.  The fields to not need to be displayed on the form.  They just need to be included in the form's RecordSource query.

In the AfterUpdate event of the checkbox:

If Me.chkyourfirld = True Then
    Me.fld1 = "something"
    Me.fld2 =  "something"
    ....
Else
    Me.fld1 = Null
    Me.fld2 = Null
    ....
End If

Never run an update query to update the record you are sitting on.  You'll get conflict error messages if the current record is dirty when you run the update query so that will force you to save the current record first before running the update query and that means that you have to save an incomplete record and that could impact your validation.  Just don't do it.
Avatar of J G
J G

ASKER

In regards to Pats comment, this is a continuous form.  so me.fld1 is dependent upon criteria where where tbl_store_Item.plu=tble_Item.PLU
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial