Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SImple Checkbox Function in Access

Status
Not open for further replies.

bgrunenb

Programmer
Jul 15, 2006
6
CA
Sorry if this is a repost... I didnt see it show up in the forum last time!!

Hi guys,

Im incredibly new to VB... I mean really new.

Heres my issue. I need to write some code into an AfterUpdate Event of a CheckBox that writes Billing Address information into the shipping address fields. Billing addresss are held under customer infomation, shipping address are held seperately in the Orders table. I need to copy to 5 fields (Unit, Street, City, St/Prov, Postal) and actually Write this information to those fields, if the checkbox is selected

Also if the check box is selected, I need those fields locked to prevent further updateing of the company billing address...

And if I change the billing address of the company I'd rather not have that update the Billing address in all previous orders... and I need a straight WRITE function.

Im thinking of using:

Me.ShippingAddress = Me.BillingAddress (for each field)
and
Me.ShippingAddress.Locked = True (or False to unlock)

in an If statement in the AfterUpdate section of the checkbox.

Will this work (I dont know how to code it specifically.. will take further research!!!)

Thanks!
 
CheckBoxes don't have an "AfterUpdate" event. That event occurs with grid controls like DBGrid (DAO) or DataGrid (ADODB). The "AfterUpdate" event fires after data have been written to the database so changes to the values in form controls will not apply to the record(s) just saved. The code you posted looks like it is concerned with changing what is displayed on the screen rather than what is stored in the database. If you are trying to save the Billing information that is contained in form controls (e.g. Me.BillingAddress, etc.) then you should probably use the BeforeUpdate Event of the grid control to set the appropriate database fields to those values BEFORE they are written to the database. Your CheckBox Click code would probably be something like
Code:
Sub myCheckBox_Click()
   Dim Locked As Boolean
   If myCheckBox.Value = vbChecked Then
      Me.ShippingAddress = Me.BillingAddress 
      [COLOR=black cyan]' etc.[/color]
      Locked = True
   Else
      Locked = False
   End If
   Me.ShippingAddress.Locked = Locked
   [COLOR=black cyan]' etc.[/color]
End Sub
and in the "BeforeUpdate" Event
Code:
   rs![ShippingAddress] = Me.ShippingAddress 
   [COLOR=black cyan]' etc.[/color]
Where "rs" is a recordset that acts as the recordsource for the grid control.
 
Hey Golom,

Thanks a million for the responce. When you say "GridControl" are you talking about the GENERAL code of the form itself?

I'm not quite sure what you're refering to as it relates to Access...

Thanks!
 
Sorry ... thought you were talking about VB ... not Access. Try forum705 (Microsoft Access Modules: VBA Coding)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top