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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement with checkbox 2

Status
Not open for further replies.

AccessApprentice

Programmer
Apr 14, 2005
14
0
0
US
How do you write an IF statement for a checkbox?

I want to copy data from one control to another if the IsMinor checkbox is checked. I have the code working to do this once the command button is clicked but I want to put this same code in the AfterUpdate event of a checkbox named IsMinor.



Private Sub SameAddress_Click()
Me!BillingAddress = Me!Address
Me!BillingCity = Me!City
Me!BillingState = Me!State
Me!BillingZip = Me!Zip
End Sub
 
AccessApprentice
Try this...

On the AfterUpdate event for the IsMinor check box, put
Code:
If Me.IsMinor = True Then
Me!BillingAddress = Me!Address
Me!BillingCity = Me!City
Me!BillingState = Me!State
Me!BillingZip = Me!Zip
End If

Tom
 
Thank you so much. This works but what do I do if the box is checked then unchecked?
 
How are ya AccessApprentice . . . . .

Since the code for the button & checkbox are both in the forms code module:
Code:
[blue]   If Me!IsMinor Then Call SameAddress_Click[/blue]
[purple]Saves writing it twice . . . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
One more question....will this work copying this same info to another form that is linked to this one.
 
AccessApprentice said:
[blue]This works but what do I do if the box is checked then unchecked?[/blue]
Well . . . what would you want to happen?

You could give the user a [blue]confirmation messagebox to continue or cancel[/blue], but that depends on what you (as the designer) wants . . . . .

Calvin.gif
See Ya! . . . . . .
 
I would like to clear the textboxes. I am very new to this so thank you so much for helping me. This code it to copy the data in one record's control to another control in that same record. Is it possible to copy this information to another form(table) that has an address,city, state,zip textbox. Say for example this is a form for the child and it is linked to a parent table by a parentid can I copy the address info from the child form to the parent form?
 
Using AceMan's central routine is the best route in my opinion since there may be more than one case where you want to populate the form. The second thing is if you want to over-write an existing entry. For example, an entry already sent / closed.

Code:
Private Sub SameAddress_Click()

If Me.IsMinor = True Then
   If Len(Me!BillingAddress & Me!BillingCity _
   & Me!BillingState & Me!BillingZip & "") Then

      If MsgBox("Over-write Billing Address?", vbOKCancel) = vbOK Then

         Me!BillingAddress = Me!Address
         Me!BillingCity = Me!City
         Me!BillingState = Me!State
         Me!BillingZip = Me!Zip

      End If

   Else

      Me!BillingAddress = Me!Address
      Me!BillingCity = Me!City
      Me!BillingState = Me!State
      Me!BillingZip = Me!Zip

   End If
End If

Richard
 
Ok. I understand the code above but is it possible for that code to copy the info to another form. Maybe I am not explaining this clearly.

I have 2 forms. One which has the client(or child's) info. Name = Clients Then other form contain the child's parent info. Name = Parents. In the client table I linked the client(child) to the parent using a parentID (M:1)....I want to have a checkbox on the child form named Minor....if the child is a minor(age 18 or less) the checkbox will be checked. Then I want a command button that when clicked will copy the address from the client form to the parent form

On the client form the address control name is address on the parent form the address control name is billingaddress. I just need some help with how to refer from one form's control to a different form's control.
 
Instead of
Me.NameOfControl

You can reference the form directly
Forms!NameOfForm!NameOfControl

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top