Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative Event for Coding Field Validation

Status
Not open for further replies.

AHJ1

Programmer
Oct 30, 2007
69
US
I expected this code to trigger when a user decided to navigate to another record. Instead, it triggers as soon as the text box is entered. Is there an event that will not trigger as soon as a user enters a text box?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo err_B4Update
    Dim boolFixThis As Boolean
    Dim strPleaseDo As String
    boolFixThis = False
    strPleaseDo = "Please do the following before saving this record: " & NP
    If Me.Dirty = True Then
        If IsNull(Me!cboCategory.Value) Then
            strPleaseDo = strPleaseDo & "* Select a category from the drop down box in step 5."
            boolFixThis = True
        End If
        If IsNull(Len(Me!cusname.Value)) Then
            strPleaseDo = strPleaseDo & vbCrLf & "* Enter a phrase name in the green box "
            boolFixThis = True
        End If
        If IsNull(Me!cboPhraseEnteredBy.Value) Then
            strPleaseDo = strPleaseDo & vbCrLf & "* Select the name of the person entering this phrase." & vbCrLf & "HINT:Double-click on the drop-down box if you need to enter a name."
            boolFixThis = True
        End If
    End If
    If boolFixThis = True Then
        MsgBox strPleaseDo, , "Additional information needed."
        
            Cancel = True
    End If
    
Exit Sub
err_B4Update:
    ErrBox "validating information before commiting to the database in frmPhrasesAdmin_Form_BeforeUpdate"
    End Sub
 
How are ya AHJ1 . . .
AHJ1 said:
[blue]Instead, it triggers as soon as the text box is entered.[/blue]
Be more specific about this! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
It appears to me that as soon as the cursor is placed in a non-active x rich-text box into which someone should copy-and-paste information that a message box is presented.

The message box advises people to satisfy the three conditions, but they have not had a chance to input their name, paste in information, etc. because the event has triggered as soon as the box receives the focus.

 
AHJ1 . . .

I'm not getting a good ping on this yet. [ponder]

Where on the form does the [blue]Rich Textbox[/blue] reside?

[blue]Post some assemblence of your form structure![/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hello Aceman1,

Thanks for checking back. I was away from the office, and just returned. Since I was trying to explain the exact setup to you, I went through the process again, from a fresh perspective, and I've come up with a solution. (Shown in the code below.) I share this to assist anyone else who might have a similar issue.

Here's the background: I've got an Access form that has a subform embedded in it. The subform contains a lightweight RichEdit control all in VB with lots of great features written by Stephen Lebans, (Highly recommended.) Part of the code that came with the module loaded the subform in the main form's load and current events.

I wrote code to force people to fill out all of the information on the main form, but as soon as the subform was entered, the validation was required. This was quite disruptive.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo err_B4Update
    Dim boolFixThis As Boolean
    Dim strPleaseDo As String
    boolFixThis = False
    'AHJ added next line 1/22/08
    Me!SubfrmRTFeditor.Form.RTFControl Me!txtcusRTF
    strPleaseDo = "Please do the following before saving this record: " & NP
    If Me.Dirty = True Then
    If Not IsNull(Me!txtcusRTF) Then
        If IsNull(Me!cboCategory.Value) Then
            strPleaseDo = strPleaseDo & "* Select a category from the drop down box in step 5."
            boolFixThis = True
        End If
        If IsNull(Len(Me!cusname.Value)) Then
            strPleaseDo = strPleaseDo & vbCrLf & "* Enter a phrase name in the green box "
            boolFixThis = True
        End If
        If IsNull(Me!cboPhraseEnteredBy.Value) Then
            strPleaseDo = strPleaseDo & vbCrLf & "* Select the name of the person entering this phrase." & vbCrLf & "HINT:Double-click on the drop-down box if you need to enter a name."
            boolFixThis = True
        End If
    End If
    If boolFixThis = True Then
        MsgBox strPleaseDo, , "Additional information needed."
            Cancel = True
        End If
    End If
 
Exit Sub
err_B4Update:
    ErrBox "validating information before commiting to the database in frmPhrasesAdmin_Form_BeforeUpdate"
    End Sub

One thing bothers me. I have created another issue. I have a work around (Resume Next in an error handler) but I do not understand what caused the issue. There's the issue: Having made the changes in the code shown above, the exit event of the subformControl now generates an error 2101-"The setting you entered isn't valid for this property." The error handling shown below works, but I still wonder I did to create this error.
Code:
Private Sub sfControl_Exit(Cancel As Integer)
Dim s As String
On Error GoTo errSFControlExit
s = Contents(SF_RTF)
If Len(s & vbNullString) > 0 Then

m_ctlRTF.Value = s
Me.Parent.Dirty = False
End If
Exit Sub
errSFControlExit:
Select Case Err.Number
    Case 2101
        Resume Next
    Case Else
        ErrBox "exiting the sfControl in sfControl_Exit on frmRTeditor"
 End Select
End Sub

Thanks, again, for your interest and assistance.
 
Bravo! AHJ1! . . .

Way ta go! . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top