Forum Moderators: open

Message Too Old, No Replies

ms access checkbox

         

nshack31

7:13 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



Im using the following on an ms access form. (the control source of chkSameShip is a yes/no field in the Database)


Private Sub chkSameShip_Click()
If Me![chkShipSame] = True Then

Me![LastNameShip] = Me![LastName]
Me![FirstNameShip] = Me![FirstName]
Me![AddressShip] = Me![Address]
Me![DistrictShip] = Me![District]
Me![CityShip] = Me![City]
Me![CountyShip] = Me![County]
Me![CountryShip] = Me![Country]
Me![PostcodeShip] = Me![Postcode]
Me![LastNameShip].Enabled = False
Me![FirstNameShip].Enabled = False
Me![AddressShip].Enabled = False
Me![DistrictShip].Enabled = False
Me![CityShip].Enabled = False
Me![CountyShip].Enabled = False
Me![CountryShip].Enabled = False
Me![PostcodeShip].Enabled = False

End If

If Me![chkShipSame] = False Then

Me![LastNameShip].Enabled = True
Me![FirstNameShip].Enabled = True
Me![AddressShip].Enabled = True
Me![DistrictShip].Enabled = True
Me![CityShip].Enabled = True
Me![CountyShip].Enabled = True
Me![CountryShip].Enabled = True
Me![PostcodeShip].Enabled = True

End If

End Sub

Basically the form lists the users name and address, if you check the box then it copies these details into the "Ship to" fields because the ship to address would be the same as the invoice address. It then disables the ship to fields to that you cant edit them However, it works but if I then scroll to the next record then the fields remain disabled even though the checkbox is not checked. Please help!

edit.. i think i need to change the "Private Sub chkSameShip_Click()" because i need it to work even if you dont click on the checkbox?

mattur

8:38 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you change records, you need to fire an event to update the display for that record. At the moment the only event code that fires is the checkbox click, so this is the only time the fields change their enabled status. No event fires when you change records, so the text boxes retain the enabled state they last had.

Been a while since I've done this, but I think you need to add the same code to the form's "On Current" event. Put it in a separate sub and call it from the checkbox click and form on current events.

nshack31

9:42 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



thanks for that, I tried adding the coding to the form onCurrent to no avail. I can see what the problem is, just having difficulty resolving it!

frustrating! Thanks so far