|
 |
access thread: Clear Tag.ctl
Message #1 by "KennethMungwira" <KennethMungwira@Y...> on Thu, 8 Nov 2001 15:10:15
|
|
Dear sir or madam,
Having problems clearing out my ctl.tag.
Please help???
Private Sub cmdEditUndo_Click()
On Error GoTo Err_cmdEditUndo_Click
Dim ctl As Control
With cmdEditUndo
If .Caption = "Change This Record" Then
' Change the font color and caption
' of the cmdEditUndo button
.Caption = "Undo All Changes"
.ForeColor = vbRed
' Change the caption of the form Headers
lblHeader1.Caption = "Edit this IA Record"
lblHeader2.Caption = "Edit this IA Record"
' Allow editing of the main and sub forms
Call FormPermits(True)
' Copy the data from each combobox's and textbox's
' Control Source property to each control's
' tag property
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
' Do the same for the subform's fields
For Each ctl In Me!subVoltConn.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!SubCommentsSubform.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!subCODate.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!ICsubStatusInfo.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
Else
' Change the font color and caption
' of the cmdEditUndo button
.Caption = "Change This Record"
.ForeColor = vbBlue
' Change the caption of the form Headers
lblHeader1.Caption = "View IA Request Data Only"
lblHeader2.Caption = "View IA Request Data Only"
' Do not allow editing of the main and sub forms
' Undo any changes by copying the data from
' the control's Tag property to the control's
' Control Source property
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 And ctl.Name <> "CommonID" Then
ctl = ctl.Tag
ctl.Tag = ""
ElseIf ctl.Name <> "CommonID" Then
ctl.Tag = ""
End If
End Select
Next ctl
' Do the same for the subform's fields
For Each ctl In Me!subVoltConn.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!SubCommentsSubform.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!subCODate.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!ICsubStatusInfo.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
Call cmdSave_Click
End If
End With
Exit_cmdEditUndo_Click:
Exit Sub
Err_cmdEditUndo_Click:
MsgBox Err.Description
Resume Exit_cmdEditUndo_Click
End Sub
Message #2 by "Carol Mandra" <carol_mandra@r...> on Thu, 8 Nov 2001 21:48:56
|
|
Hi, Uhmmmmmm...
First, since you repeat the same exact code many times, copy it out into
a procedure and then make calls to the procedure. This will make the code
less error prone and easier to debug. See sample procedure below. To call
the procedure, see the code sample below also, in the cmdEditUndo_Click()
module. The syntax below is correct, but you need to change the if
statements to be what you want. This will start you off.
I noticed a syntax error in one spot in the code:
Me!subVoltConn.Form
- correct way is
Me!subVoltConn.Form.Controls
If you get error messages, run the code through the debugger with break
points set to see what line is giving the error, and write down the error
number and message if it still isn't working. This works in Access 97.
You can look up Controls Container in Access Help for more information.
Ciao, Carol :-)
Private Sub cmdEditUndo_Click()
If Undo = true Then 'whatever your if criteria is
Call FormPermits(True)
Call CopyFromTagToControl(me)
' Do the same for the subform's fields
Call SetTag(Me!subVoltConn.Form)
Call SetTag(Me!SubCommentsSubform.Form)
Call SetTag(Me!subCODate.Form)
Call SetTag(Me!ICsubStatusInfo.Form)
End If
End Sub
=====================================================
Proc SetTag(myFrm as Form)
'Copy the data from each combo & textbox's Control Source property to each
control's tag property, I think
Dim ctl as control
'myfrm = Me!subVoltConn.Form.Controls - missing the ".Controls" in your
code
For Each ctl In myFrm.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
ctl.Tag = ""
End If
End Select
Next ctl
End proc
===============================================================
> Proc CopyFromTagToControl(myFrm as Form)
'Copy the data from each combo & textbox's tag property to its Control
property....
dim ctl as Control
For Each ctl In myFrm.Controls 'Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 And ctl.Name <> "CommonID" Then
ctl = ctl.Tag
ctl.Tag = ""
End If
End Select
Next ctl
End proc
Message #3 by "KennethMungwira" <KennethMungwira@Y...> on Wed, 21 Nov 2001 15:31:15
|
|
Just verify that TAg is Cleared.
Option Compare Database
Option Explicit
Dim fOK As Boolean
Private Sub FormBoolean(bolOK As Boolean)
With Me
.AllowEdits = bolOK
!subVoltConn.Form.AllowEdits = bolOK
!subVoltConn.Form.AllowAdditions = bolOK
!subVoltConn.Form.AllowDeletions = bolOK
!ICsubStatusInfo.Form.AllowEdits = bolOK
!ICsubStatusInfo.Form.AllowAdditions = bolOK
!ICsubStatusInfo.Form.AllowDeletions = bolOK
!subComments.Form.AllowEdits = bolOK
!subComments.Form.AllowAdditions = bolOK
!subComments.Form.AllowDeletions = bolOK
!subDates.Form.AllowEdits = bolOK
!subDates.Form.AllowAdditions = bolOK
!subDates.Form.AllowDeletions = bolOK
!SubSinkForm.Form.AllowEdits = bolOK
!SubSinkForm.Form.AllowAdditions = bolOK
!SubSinkForm.Form.AllowDeletions = bolOK
End With
RefID.SetFocus
' Hide the cmdSave button if it is visible
cmdSave.Visible = bolOK
End Sub
Private Sub cmdEditUndo_Click()
On Error GoTo Err_cmdEditUndo_Click
Dim ctl As Control
With cmdEditUndo
If .Caption = "Change This Record" Then
' Change the font color and caption
' of the cmdEditUndo button
.Caption = "Undo All Changes"
.ForeColor = vbRed
' Change the caption of the form Headers
lblHeader1.Caption = "Edit this IC Planning Record"
lblHeader2.Caption = "Edit this IC Planning Record"
' Allow editing of the main and sub forms
Call FormBoolean(True)
' Copy the data from each combobox's and textbox's
' Control Source property to each control's
' tag property
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
If ctl.Name <> "txtBusID" And ctl.Name
<> "CommentID" Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End If
End Select
Next ctl
' Do the same for the subform's fields
For Each ctl In Me!subVoltConn.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!SubSinkForm.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!ICsubStatusInfo.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
If ctl.Name <> "txtDaysToComplete" Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End If
End Select
Next ctl
For Each ctl In Me!subComments.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!subDates.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Not IsNull(ctl) Then
ctl.Tag = ctl
Else
ctl.Tag = ""
End If
End Select
Next ctl
Else
' Change the font color and caption
' of the cmdEditUndo button
.Caption = "Change This Record"
.ForeColor = vbBlue
' Change the caption of the form Headers
lblHeader1.Caption = "View IC Planning Data Only"
lblHeader2.Caption = "View IC Planning Data Only"
' Undo any changes by copying the data from
' the control's Tag property to the control's
' Control Source property
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 And ctl.Name <> "CommonID" And
ctl.Name <> "txtBusID" Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
' Do the same for the subform's fields
For Each ctl In Me!subVoltConn.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!SubSinkForm.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!ICsubStatusInfo.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!subComments.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 And ctl.Name <> "CommonID" And
ctl.Name <> "txtBusID" Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
For Each ctl In Me!subDates.Form
Select Case ctl.ControlType
Case acComboBox, acTextBox
If Len(ctl.Tag) > 0 Then
ctl = ctl.Tag
Else
ctl.Tag = ""
End If
End Select
Next ctl
Call cmdSave_Click
End If
End With
Exit_cmdEditUndo_Click:
Exit Sub
Err_cmdEditUndo_Click:
MsgBox Err.Description
Resume Exit_cmdEditUndo_Click
End Sub
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
With cmdEditUndo
.Caption = "Change This Record"
.ForeColor = vbBlue
End With
lblHeader1.Caption = "View IA Planning Requests"
lblHeader2.Caption = "View IA Planning Requests"
Call FormBoolean(False)
Exit_cmdSave_Click:
RefID.SetFocus
cmdSave.Visible = False
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txtNTID.Value = GetNTUserID
Me.txtNTID2.Value = GetNTUserID
End Sub
Private Sub Form_Current()
On Error GoTo Form_Current_ERR
' Change the cmdEditUndo caption and
' font color. Change the form's headers
' captions and do not permit editing of
' any records when we move to another
' record.
If Me.AllowAdditions = True Then
cmdEditUndo.Visible = False
lblHeader1.Caption = "Add IA Planning Requests"
lblHeader2.Caption = "Add IA Planning Requests"
ElseIf Me.AllowEdits = True Then
With cmdEditUndo
.Caption = "Change This Record"
.ForeColor = vbBlue
End With
lblHeader1.Caption = "View IA Planning Requests"
lblHeader2.Caption = "View IA Planning Requests"
Call FormBoolean(False)
End If
Form_Current_EXIT:
Exit Sub
Form_Current_ERR:
If Err.Number = 2448 Then Resume Next
MsgBox Err.Description
Resume Form_Current_EXIT
End Sub
Private Sub Form_Load()
' Call warning
End Sub
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
|
|
 |