Help with coding

  • Thread starter Thread starter Suzanne Wyatt
  • Start date Start date
S

Suzanne Wyatt

Network Blitz
Below is the current code I have in my database, thanks to some help from PC
Datasheet! Question I have is two fold, I have a checkbox called
SuccessfulContact, how and where would I put an event to 1. make the
SfrmClientResponse not visible unless the value of SuccessfulContact Check
box is true(IsNotNull) Second I would like to lock the combobox IntervalID
until SuccessfulContact is made (same checkbox) I have a main form
FrmClient with 2 subforms Sfrm Survey and Sfrm ClientResponse. All help
would be greatly appreciated. TIA Suzanne Wyatt

Private Sub Form_Current()
Me!ProgramCategoryID.Requery
Me!ProgramCategoryID.SetFocus
End Sub

Private Sub ProgramCategoryID_AfterUpdate()
Me!ProgramID.Requery
End Sub

Private Sub FindClientNum_Enter()
Me!FindClientNum.Dropdown
End Sub

Private Sub FindClientNum_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientNum
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientNum = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Private Sub FindClientLastName_Enter()
Me!FindClientLastName.Dropdown
End Sub

Private Sub FindClientLastName_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientLastName
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientLastName = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Option Compare Database
Private Sub cbxSurveyResponse_AfterUpdate()
Me!SurveyResponseID = Me!cbxSurveyResponse
Me!cbxSurveyResponse = Null
Me!SurveyID = Forms!FrmClient!SfrmSurvey!SurveyID
End Sub
Private Sub Form_Current()
Me!cbxSurveyResponse.Requery
End Sub
Option Compare Database
Option Explicit
Private Sub Form_Current()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
If Rst.RecordCount <> 0 Then
Rst.MoveLast
End If
' deactivate the previous button when on the first record
Me!PrevRec.Enabled = (Me.CurrentRecord <> 1)
' deactivate the next button when on the last record
Me!NextRec.Enabled = (Me.CurrentRecord < Rst.RecordCount)
If Me.NewRecord Then
Me!LblRecNum.Caption = "New"
Me!NewRec.Enabled = False
Else
With Rst
.Bookmark = Me.Bookmark
Me!LblRecNum.Caption = Me.CurrentRecord & " of " & .RecordCount
End With
End If
Rst.Close
Set Rst = Nothing
End Sub
Private Sub IntervalID_AfterUpdate()
Me!NextRec.Enabled = True
Me!NewRec.Enabled = True
End Sub
Private Sub SfrmClientResponse_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub SfrmSurveyContact_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub NextRec_Click()
DoCmd.GoToRecord , , acNext
End Sub
Private Sub PrevRec_Click()
DoCmd.GoToRecord , , acPrevious
Me!NewRec.Enabled = True
End Sub
Private Sub NewRec_Click()
DoCmd.GoToRecord , , acNewRec
End Sub
 
To clarify... You have a form with a Checkbox, a Combobox
and a Subform (maybe some other controls, but not
important for this question).

You want the Combobox to be locked and the Subform to be
invisible unless the Checkbox is ticked (true) upon which
you want the Combobox to be unlocked and the Subform to be
visible.

If this is correct then all you need do is use the
AfterUpdate event for the Checkbox. I have created a test
form with the three controls and written the following
code:

Private Sub chk_CheckBox1_AfterUpdate()
'cbo_TestCombo.Locked = Not chk_CheckBox1
cbo_TestCombo.Enabled = chk_CheckBox1

subfrm_1.Visible = chk_CheckBox1
End Sub

The properties of the controls you wish to change are all
boolean (True or False). As a Checkbox is also a Boolean
type, you can use the value of the Checkbox to drive the
properties of the other controls.

I have commented the locking of the combo and substituted
it with the enabled property as this has a more visual
impact, however make your changes as appropriate.

Bish...
-----Original Message-----
Network Blitz
Below is the current code I have in my database, thanks to some help from PC
Datasheet! Question I have is two fold, I have a checkbox called
SuccessfulContact, how and where would I put an event to 1. make the
SfrmClientResponse not visible unless the value of SuccessfulContact Check
box is true(IsNotNull) Second I would like to lock the combobox IntervalID
until SuccessfulContact is made (same checkbox) I have a main form
FrmClient with 2 subforms Sfrm Survey and Sfrm ClientResponse. All help
would be greatly appreciated. TIA Suzanne Wyatt

Private Sub Form_Current()
Me!ProgramCategoryID.Requery
Me!ProgramCategoryID.SetFocus
End Sub

Private Sub ProgramCategoryID_AfterUpdate()
Me!ProgramID.Requery
End Sub

Private Sub FindClientNum_Enter()
Me!FindClientNum.Dropdown
End Sub

Private Sub FindClientNum_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientNum
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientNum = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Private Sub FindClientLastName_Enter()
Me!FindClientLastName.Dropdown
End Sub

Private Sub FindClientLastName_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientLastName
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientLastName = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Option Compare Database
Private Sub cbxSurveyResponse_AfterUpdate()
Me!SurveyResponseID = Me!cbxSurveyResponse
Me!cbxSurveyResponse = Null
Me!SurveyID = Forms!FrmClient!SfrmSurvey!SurveyID
End Sub
Private Sub Form_Current()
Me!cbxSurveyResponse.Requery
End Sub
Option Compare Database
Option Explicit
Private Sub Form_Current()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
If Rst.RecordCount <> 0 Then
Rst.MoveLast
End If
' deactivate the previous button when on the first record
Me!PrevRec.Enabled = (Me.CurrentRecord <> 1)
' deactivate the next button when on the last record
Me!NextRec.Enabled = (Me.CurrentRecord < Rst.RecordCount)
If Me.NewRecord Then
Me!LblRecNum.Caption = "New"
Me!NewRec.Enabled = False
Else
With Rst
.Bookmark = Me.Bookmark
Me!LblRecNum.Caption = Me.CurrentRecord & " of " & .RecordCount
End With
End If
Rst.Close
Set Rst = Nothing
End Sub
Private Sub IntervalID_AfterUpdate()
Me!NextRec.Enabled = True
Me!NewRec.Enabled = True
End Sub
Private Sub SfrmClientResponse_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub SfrmSurveyContact_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub NextRec_Click()
DoCmd.GoToRecord , , acNext
End Sub
Private Sub PrevRec_Click()
DoCmd.GoToRecord , , acPrevious
Me!NewRec.Enabled = True
End Sub
Private Sub NewRec_Click()
DoCmd.GoToRecord , , acNewRec
End Sub


.
 
So it would be on the after update event of only the check box and not in
the on current event of the main form?
Bish said:
To clarify... You have a form with a Checkbox, a Combobox
and a Subform (maybe some other controls, but not
important for this question).

You want the Combobox to be locked and the Subform to be
invisible unless the Checkbox is ticked (true) upon which
you want the Combobox to be unlocked and the Subform to be
visible.

If this is correct then all you need do is use the
AfterUpdate event for the Checkbox. I have created a test
form with the three controls and written the following
code:

Private Sub chk_CheckBox1_AfterUpdate()
'cbo_TestCombo.Locked = Not chk_CheckBox1
cbo_TestCombo.Enabled = chk_CheckBox1

subfrm_1.Visible = chk_CheckBox1
End Sub

The properties of the controls you wish to change are all
boolean (True or False). As a Checkbox is also a Boolean
type, you can use the value of the Checkbox to drive the
properties of the other controls.

I have commented the locking of the combo and substituted
it with the enabled property as this has a more visual
impact, however make your changes as appropriate.

Bish...
-----Original Message-----
Network Blitz
Below is the current code I have in my database, thanks to some help from PC
Datasheet! Question I have is two fold, I have a checkbox called
SuccessfulContact, how and where would I put an event to 1. make the
SfrmClientResponse not visible unless the value of SuccessfulContact Check
box is true(IsNotNull) Second I would like to lock the combobox IntervalID
until SuccessfulContact is made (same checkbox) I have a main form
FrmClient with 2 subforms Sfrm Survey and Sfrm ClientResponse. All help
would be greatly appreciated. TIA Suzanne Wyatt

Private Sub Form_Current()
Me!ProgramCategoryID.Requery
Me!ProgramCategoryID.SetFocus
End Sub

Private Sub ProgramCategoryID_AfterUpdate()
Me!ProgramID.Requery
End Sub

Private Sub FindClientNum_Enter()
Me!FindClientNum.Dropdown
End Sub

Private Sub FindClientNum_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientNum
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientNum = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Private Sub FindClientLastName_Enter()
Me!FindClientLastName.Dropdown
End Sub

Private Sub FindClientLastName_AfterUpdate()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Me!FindClientLastName
Me.Bookmark = Rst.Bookmark
Rst.Close
Me!FindClientLastName = Null
Me!SfrmSurvey.SetFocus
Me!SfrmSurvey!IntervalID.SetFocus
End Sub

Option Compare Database
Private Sub cbxSurveyResponse_AfterUpdate()
Me!SurveyResponseID = Me!cbxSurveyResponse
Me!cbxSurveyResponse = Null
Me!SurveyID = Forms!FrmClient!SfrmSurvey!SurveyID
End Sub
Private Sub Form_Current()
Me!cbxSurveyResponse.Requery
End Sub
Option Compare Database
Option Explicit
Private Sub Form_Current()
Dim Rst As Recordset
Set Rst = Me.RecordsetClone
If Rst.RecordCount <> 0 Then
Rst.MoveLast
End If
' deactivate the previous button when on the first record
Me!PrevRec.Enabled = (Me.CurrentRecord <> 1)
' deactivate the next button when on the last record
Me!NextRec.Enabled = (Me.CurrentRecord < Rst.RecordCount)
If Me.NewRecord Then
Me!LblRecNum.Caption = "New"
Me!NewRec.Enabled = False
Else
With Rst
.Bookmark = Me.Bookmark
Me!LblRecNum.Caption = Me.CurrentRecord & " of " & .RecordCount
End With
End If
Rst.Close
Set Rst = Nothing
End Sub
Private Sub IntervalID_AfterUpdate()
Me!NextRec.Enabled = True
Me!NewRec.Enabled = True
End Sub
Private Sub SfrmClientResponse_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub SfrmSurveyContact_Enter()
If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
MsgBox "You Must Enter The Interval First!", , "What Is The Interval?"
Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
End If
End Sub
Private Sub NextRec_Click()
DoCmd.GoToRecord , , acNext
End Sub
Private Sub PrevRec_Click()
DoCmd.GoToRecord , , acPrevious
Me!NewRec.Enabled = True
End Sub
Private Sub NewRec_Click()
DoCmd.GoToRecord , , acNewRec
End Sub


.
 
Suzanne,

You are correct that the same code will need to be executed on the OnCurrent
event of the Form. you caould achieve this most easily by calling the
checkbox AfterUpdate event directly from the FormCurrent event as in the
following:

Private Sub FormCurrent()
Me!ProgramCategoryID.Requery
Me!ProgramCategoryID.SetFocus
SuccessfulContact.AfterUpdate
End Sub

Hope this helps.

Eric



| So it would be on the after update event of only the check box and not in
| the on current event of the main form?
| | > To clarify... You have a form with a Checkbox, a Combobox
| > and a Subform (maybe some other controls, but not
| > important for this question).
| >
| > You want the Combobox to be locked and the Subform to be
| > invisible unless the Checkbox is ticked (true) upon which
| > you want the Combobox to be unlocked and the Subform to be
| > visible.
| >
| > If this is correct then all you need do is use the
| > AfterUpdate event for the Checkbox. I have created a test
| > form with the three controls and written the following
| > code:
| >
| > Private Sub chk_CheckBox1_AfterUpdate()
| > 'cbo_TestCombo.Locked = Not chk_CheckBox1
| > cbo_TestCombo.Enabled = chk_CheckBox1
| >
| > subfrm_1.Visible = chk_CheckBox1
| > End Sub
| >
| > The properties of the controls you wish to change are all
| > boolean (True or False). As a Checkbox is also a Boolean
| > type, you can use the value of the Checkbox to drive the
| > properties of the other controls.
| >
| > I have commented the locking of the combo and substituted
| > it with the enabled property as this has a more visual
| > impact, however make your changes as appropriate.
| >
| > Bish...
| >
| > >-----Original Message-----
| > >Network Blitz
| > >Below is the current code I have in my database, thanks
| > to some help from PC
| > >Datasheet! Question I have is two fold, I have a
| > checkbox called
| > >SuccessfulContact, how and where would I put an event to
| > 1. make the
| > >SfrmClientResponse not visible unless the value of
| > SuccessfulContact Check
| > >box is true(IsNotNull) Second I would like to lock the
| > combobox IntervalID
| > >until SuccessfulContact is made (same checkbox) I have a
| > main form
| > >FrmClient with 2 subforms Sfrm Survey and Sfrm
| > ClientResponse. All help
| > >would be greatly appreciated. TIA Suzanne Wyatt
| > >
| > >Private Sub Form_Current()
| > >Me!ProgramCategoryID.Requery
| > >Me!ProgramCategoryID.SetFocus
| > >End Sub
| > >
| > >Private Sub ProgramCategoryID_AfterUpdate()
| > >Me!ProgramID.Requery
| > >End Sub
| > >
| > >Private Sub FindClientNum_Enter()
| > >Me!FindClientNum.Dropdown
| > >End Sub
| > >
| > >Private Sub FindClientNum_AfterUpdate()
| > >Dim Rst As Recordset
| > >Set Rst = Me.RecordsetClone
| > >Rst.FindFirst "[ClientID] = " & Me!FindClientNum
| > >Me.Bookmark = Rst.Bookmark
| > >Rst.Close
| > >Me!FindClientNum = Null
| > >Me!SfrmSurvey.SetFocus
| > >Me!SfrmSurvey!IntervalID.SetFocus
| > >End Sub
| > >
| > >Private Sub FindClientLastName_Enter()
| > >Me!FindClientLastName.Dropdown
| > >End Sub
| > >
| > >Private Sub FindClientLastName_AfterUpdate()
| > >Dim Rst As Recordset
| > >Set Rst = Me.RecordsetClone
| > >Rst.FindFirst "[ClientID] = " & Me!FindClientLastName
| > >Me.Bookmark = Rst.Bookmark
| > >Rst.Close
| > >Me!FindClientLastName = Null
| > >Me!SfrmSurvey.SetFocus
| > >Me!SfrmSurvey!IntervalID.SetFocus
| > >End Sub
| > >
| > >Option Compare Database
| > >Private Sub cbxSurveyResponse_AfterUpdate()
| > >Me!SurveyResponseID = Me!cbxSurveyResponse
| > >Me!cbxSurveyResponse = Null
| > >Me!SurveyID = Forms!FrmClient!SfrmSurvey!SurveyID
| > >End Sub
| > >Private Sub Form_Current()
| > >Me!cbxSurveyResponse.Requery
| > >End Sub
| > >Option Compare Database
| > >Option Explicit
| > >Private Sub Form_Current()
| > >Dim Rst As Recordset
| > >Set Rst = Me.RecordsetClone
| > >If Rst.RecordCount <> 0 Then
| > > Rst.MoveLast
| > >End If
| > >' deactivate the previous button when on the first record
| > >Me!PrevRec.Enabled = (Me.CurrentRecord <> 1)
| > >' deactivate the next button when on the last record
| > >Me!NextRec.Enabled = (Me.CurrentRecord < Rst.RecordCount)
| > >If Me.NewRecord Then
| > > Me!LblRecNum.Caption = "New"
| > > Me!NewRec.Enabled = False
| > >Else
| > > With Rst
| > > .Bookmark = Me.Bookmark
| > > Me!LblRecNum.Caption = Me.CurrentRecord & " of "
| > & .RecordCount
| > > End With
| > >End If
| > >Rst.Close
| > >Set Rst = Nothing
| > >End Sub
| > >Private Sub IntervalID_AfterUpdate()
| > >Me!NextRec.Enabled = True
| > >Me!NewRec.Enabled = True
| > >End Sub
| > >Private Sub SfrmClientResponse_Enter()
| > >If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
| > > MsgBox "You Must Enter The Interval First!", , "What Is
| > The Interval?"
| > > Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
| > >End If
| > >End Sub
| > >Private Sub SfrmSurveyContact_Enter()
| > >If IsNull(Forms!FrmClient!SfrmSurvey!SurveyID) Then
| > > MsgBox "You Must Enter The Interval First!", , "What Is
| > The Interval?"
| > > Forms!FrmClient!SfrmSurvey!IntervalID.SetFocus
| > >End If
| > >End Sub
| > >Private Sub NextRec_Click()
| > >DoCmd.GoToRecord , , acNext
| > >End Sub
| > >Private Sub PrevRec_Click()
| > >DoCmd.GoToRecord , , acPrevious
| > >Me!NewRec.Enabled = True
| > >End Sub
| > >Private Sub NewRec_Click()
| > >DoCmd.GoToRecord , , acNewRec
| > >End Sub
| > >
| > >
| > >.
| > >
|
|
 
Back
Top