Optional Address in Form

  • Thread starter Thread starter DMWM
  • Start date Start date
D

DMWM

Hi,

I'm creating a booking system for an embroidery company. Their customers
either collect or have their items delivered. I want to create an option on
the form where the delivery address can only be entered (fields become
unlocked/enabled) when the collection yes/no option is not ticked.

Any help would be great. Also, sorry if this question has already been asked
I've searched but couldnt find anything to help me.

Thanks in advance

DMWM
 
On Sun, 19 Jul 2009 05:42:00 -0700, DMWM

In that checkbox AfterUpdate event write:
dim blnNeedsAddress as Boolean
blnNeedsAddress = not myCheckbox
myAddress.Locked = not blnNeedsAddress
myCity.Locked = not blnNeedsAddress
myState.Locked = not blnNeedsAddress
myZip.Locked = not blnNeedsAddress
(of course you replace myObjectNames with yours)

-Tom.
Microsoft Access MVP
 
DMWM,
One method would be to make the address fields Enabled = True,
and Locked = False by default.
Use the AfterUpdate event of your check box (ex. chkShipped) = True to
enable the address controls.

Private Sub chkShipped_AfterUpdate()
If chkShipped = True Then
[ShippedName].Enabled = True
[ShippedAddress1].Enabled = True
' etc for all address fields
Else
[ShippedName].Enabled = False
[ShippedAddress1].Enabled = False
' etc for all address fields
End If
End Sub

Also, use that same code in your form's OnCurrent event,
so that the address fields will eanble/disable correctly... according
to the chkShipped value... when browsing from record to record.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
Open the form with the delivery address fields locked, disabled or both. In
the AfterUpdate event of the checkbox, you'll need some code similar to:

Sub CheckboxName_AfterUpdate()

If Me.CheckboxName = True Then
Me.txtDeliveryAddress.Enabled = True
Me.txtDeliveryCity.Enabled = True
Me.txtDeliveryState.Enabled = True
Me.txtDeliveryZip.Enabled = True
Me.txtDeliveryAddress.Locked = False
Me.txtDeliveryCity.Locked = False
Me.txtDeliveryState.Locked = False
Me.txtDeliveryZip.Locked = False
Else
Me.txtDeliveryAddress.Enabled = False
Me.txtDeliveryCity.Enabled = False
Me.txtDeliveryState.Enabled = False
Me.txtDeliveryZip.Enabled = False
Me.txtDeliveryAddress.Locked = True
Me.txtDeliveryCity.Locked = True
Me.txtDeliveryState.Locked = True
Me.txtDeliveryZip.Locked = True
End Sub

You will also have to call the sub from the form's Current event.
 
Thank you for the code, much appreciated.

In Addition,

I can't see the OnCurrent event for the form, is this the same as OnClick?

Thanks
 
DMWM,
Make sure you click on the empty background area of your report design.
Be sure the Properties Dialog Box indicates "Form" in the dialog title
bar.
Select the Properties Dialog Box "All" tab.
Scroll down to the On Current property.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
Thanks for all the help. Worked brilliantly! :)

Arvin Meyer said:
The Current event should be seen from the event list on the property sheet.
If you can't find it, just add this code to the form's module and compile
it:

Private Sub Form_Current()
CheckboxName_AfterUpdate
End Sub

Of course you'll need to use the correct name for the checkbox to replace
"CheckboxName"
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
Back
Top