Solved

Update a field based on whether a button is checked or not

Posted on 2013-10-30
4
274 Views
Last Modified: 2013-10-30
I have this form that needs to do the following

When the checkbox named "Assigned" is checked I need the field "ContolTNum " to be assigned the value from a second form named Forms!frm1POSControlTicket!ControlTicketNum. When the button is unchecked the field should be null

currently the code I have is as follows

Private Sub Assigned_Click()
Me.Refresh
Forms!frm_qry_tbl_visa_imports!ContolTNum = Forms!frm1POSControlTicket!ControlTicketNum

End Sub

Open in new window


Obviously as you can guess everytime i check or uncheck the box, the field updates to the set value. I do need to add some logic that when the button is unchecked to convert the field back to null (not assign a value to the field.

thanks
Vinnie
experts1.JPG
0
Comment
Question by:damixa
  • 2
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39612752
Try this:

Private Sub Assigned_Click()
Me.Refresh
If Me.Assigned = true then
    Forms!frm_qry_tbl_visa_imports!ContolTNum = Forms!frm1POSControlTicket!ControlTicketNum
Else
    Forms!frm_qry_tbl_visa_imports!ContolTNum = Null
End if 
End Sub

Open in new window

0
 

Author Comment

by:damixa
ID: 39612759
Hi,
The problem is that it does not go back to null once i Uncheck it

I need it to go null once i Uncheck "Assigned
0
 

Author Comment

by:damixa
ID: 39612762
Perfect, sorry my bad, I didnt read the whole code
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39612763
Also - I think I mentioned this in another question - you do not need the full form reference if the code is on the same form:

Try this if the code is on frm_qry_tbl_visa_imports:

Private Sub Assigned_Click()
Me.Refresh
If Me.Assigned = true then
    Me.ContolTNum = Forms!frm1POSControlTicket!ControlTicketNum
Else
    Me.ContolTNum = Null
End if 
End Sub

Open in new window


Or this if it is on frm1POSControlTicket:

Private Sub Assigned_Click()
Me.Refresh
If Me.Assigned = true then
    Forms!frm_qry_tbl_visa_imports.ContolTNum = Me.ControlTicketNum
Else
    Forms!frm_qry_tbl_visa_imports.ContolTNum = Null
End if 
End Sub

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question