Need help with code for checkbox

dakcg

Registered User.
Local time
Today, 16:35
Joined
Aug 24, 2001
Messages
88
Greetings. I am in the middle of creating a database, and I have a problem: On a form, there are checkboxes, when a box is checked, I want to open a popup form that asks for additional information. Now, I have created the popup forms and they do report back to the table. The problem is, the popup form appears if the checkbox is checked, and when it is unchecked! I created a simple code that says when checkbox is Yes then open form. So why does it open if the checkbox is No?

Any help is appreciated.

Thanks

DAKCG
 
Use OnUpdate event to clarify the check box status.

Private Sub Check0_AfterUpdate()
If Me.Check0 = True Then
MsgBox "The check box is TRUE now", vbOKOnly
End If
End Sub
 
It would be much simpler to troubleshoot your problem if you posted the procedure you are using.

RDH
 
Code used

Here is the code I use:


Private Sub Injured_AfterUpdate()
If (True) Then
DoCmd.OpenForm "frmInjuryPF", acNormal, "", "", , acNormal
End If
End Sub

Thanks for any help
 
Thank you, Rich

I used the code you suggested and it worked perfectly. I am new to code, and I have alot to learn, thank you for your contribution to that knowledge.

Ddakcg
 
If nz(me!Injured) then - it's true

If the chkeckbox is never initialized

If me!Injured then --- results in an error
 
=True removes the need for Nz, and since the code is on the After Update of the control not the Form_Current Nz isn't required
 
I'm using the above code for a checkbox, but the subform that appears doesn't automatically go to the right record.
When the checkbox is clicked, a subform will open with contact info, but it always opens the contactinfo with ID 1. So when I click the checkbox on a person with ID 120, it will open the contact inforation of the person with ID 1 and not the ID 120 person....

Plz help
 
You have to filter the subform recordsource with the ID value. Your posting is not clear where the filter value is coming from.

One way to accomplish your desired result, on YourchkBox AfterUpdate event:

if me!yourchkbox = true then
forms!MainForm!SubForm.filter = "[FilteredFieldNam]=" & 120
forms!MainForm!SubForm.filteron = true
forms!MainForm!SubForm.requery
end if

I don't know where you get the "120" value.

On the main form Form_Open event, set
forms!MainForm!SubForm.filteron = false
so that data is not innitiallo filtered, on set
forms!MainForm!SubForm.filter = "[FilteredFieldNam]=" & -1
forms!MainForm!SubForm.filteron = true
forms!MainForm!SubForm.requery

where -1 is never a valid filter value.

Another way to do this would be to have a two column combo box with the first column hidden and being the ID value. Select, then filter on AfterUpdate event.

forms!MainForm!SubForm.filter = "[FilteredFieldNam]=" & _
Me!combobox
forms!MainForm!SubForm.filteron = true
forms!MainForm!SubForm.requery

this way multiple checkboxes are eliminated. column 1 of the combobox rowsouorce is the ID, column 2 the description.
 
You have to use the Where condition, something like
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "MyForm"

stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Thanx, It works perfectly now.

I still have one problem on another checkbox:
I tried to use the same code, but then the subform that pops up can't be used properly. It does open, and I can change everything in it, but it won't store the record, becouse it doesn't take over the personID from the main form. How can I get this to work?

Another solutioon for this might be using a subform on the main form, but it needs the following specifications:

When the form loads, access needs to check whether chkTourist (the checkbox) is checked, if it is not, subform frmCuracao needs to be locked and disabled, when it is checked, it needs to be unlocked and enabled. (visibla / not visible can also be handy)

So for example when I switch from a record where chkTourist is checked, to a record where chkTourist is unchecked, the subform needs to change from enabled/unlocked(/visible) to disabled/locked(/not visible).

Can anyone help me out on this one?? Thanks
 

Users who are viewing this thread

Back
Top Bottom