Hi All,
Okay I know this shouldn't be so difficult but apparently it is. I am trying to set the value of a checkbox on one of my forms based on other information on that form. The code is pretty simple, some variation of:
Code:
If control A = criteria Then
Me.CheckBox.Value = -1
Else
Me.CheckBox.Value = 0
End If
This is set to the On Current event.
I've seen some posts saying you can't set values of checkboxes or other controls after the form has loaded but here is the confusing part, I have another form that does almost the exact same thing and it works just fine. The code for that is shown below:
Code:
Private Sub btnACC_Click()
Dim strSQL, strINSERT As String, rst As DAO.Recordset, db As DAO.Database, Response As Variant
' Collecting any Outside Employment entries that are part of this Annual Report
strSQL = "SELECT * FROM ARACC WHERE ARACC.ARPTID = " & fARPTID & ";"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
' If there is at least 1 Accomplishment record then we just go to the form
If Not rst.BOF And Not rst.EOF Then
GoTo FormOpen
Else ' If there are no records of Outside Employment for this annual report, we initialize one
'Checking to make sure this is what they meant to do
Response = MsgBox("No Accomplishment records exist for this Annual Report. Do you want to create one?", _
vbYesNo + vbQuestion, "No Current Records")
Select Case Response
Case vbYes ' If we want to add a record, we add it
strINSERT = "INSERT INTO ARACC (ARPTID) VALUES (" & fARPTID & ")"
'Debug.Print strINSERT
CurrentDb.Execute strINSERT
Me.ARACC.Value = -1
GoTo FormOpen
Case vbNo 'Whoops! My mistake, let's get out of here
GoTo MyExit
Case Else
GoTo MyExit
End Select
End If
MyExit:
Set db = Nothing
Set rst = Nothing
Exit Sub
FormOpen:
Set db = Nothing
Set rst = Nothing
DoCmd.OpenForm "frmARACC", acNormal, , "[ARPTID] = " & fARPTID & ""
End Sub
See that Me. ARACC.Value = -1? Yup, that's my checkbox control and this code effectively sets the value of that checkbox with no hangups. Why does it work without a hiccup here but not before? I'd really appreciate any light anyone might feel like shedding on this.
Thanks!
Ryan