In my VB 6.0 project, I have a form in which the user enters a number and hits 'enter', and the validation trigger fires without issue. I moved this logic and column to the login form, and it no longer works. The validation will fire if I manually click on another column, however, clicking 'enter' no longer fires the validation.
Is there some sort of form setting set-up that I am overlooking? Why the #&#! will this simple logic work in one place and not another??
Thanks in advance.
Silly me, the validation that was working when the user clicked enter included this code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then 'enter key
SendKeys "{tab}"
End If
End Sub
I solved my own problem, but figured I would post it in case someone else wanted validation to fire when the user clicks 'enter'.
Related
I have a simple unbound access 2016 form. On the form, I have several controls including text and combo boxes. On the first text box control I would like to require a data value (underlying table field data type is short text).
I have set the Validation Rule property for the control in the property sheet to "Is Not Null" and added an appropriate validation text message.
For an unknown reason I have not been able to get this validation rule to ever fire. I have cleared the validation rule on the table to make sure it wasn't interfering, however, no luck.
It's like the validation check is not happening when focus leaves the control. There is no other event procedure that has been written that would interfere either.
Thanks for the help.
You can give the control a default value, then
Form_load()
Yourcontrol.setfocus
Sendkeys "{DEL}"
The requirement was to validate the control for a missing value using the validation rule when the control lost focus (ie user tabbed out of text box without ever entering a value). I wanted the user to get immediate feedback that they needed to provide a value for the given control.
As Rene pointed out in the comments, the validation rule does not fire unless there has been a value change.
The Sendkeys solution has issues, I only use Sendkeys as a last resort.
The solution in this case was to put the validation test in the Control_OnExit event handler. The user gets immediate feedback as desired and does not wait until the record is submitted.
One further note that could easily be missed; in an unbound form, the before_update event will never fire.
I have a situation similar to the following simplified description:
A form with a TextBox (call it txtQty) in which a user can enter an integer. The event txtQty_Validate is used to validate the user input and force them to correct any errors before changing focus. This works great with all other controls on the form except for said txtQty. I assume that this is because the Cancel button on the form has the property CausesValidation necessarily set to false; thus when the user Tabs from txtQty to the Cancel button (whose TabIndex is next) it does not appropriately trigger the txtQty_Validation event.
My first instinct was to simply go to the txtQty_KeyPress event (which I am already using to make the RETURN key behave as TAB key) and capture the TAB key and temporarily toggle the CausesValidation property to allow the txtQty_Validation event to fire. However, it seems as though capturing the TAB key is not as easy as I had thought it would be.
Any suggestions? I assume that this cannot be the first time anybody creating a Form has come across such a situation.
Thanks
You could try this in the Cancel GotFocus event.
Dim b As Boolean
Call txtQty_Validate(b)
If b Then txtQty.SetFocus
Assuming you have something like this
Private Sub txtQty_Validate(Cancel As Boolean)
If Not IsNumeric(txtQty.Text) Then
Cancel = True
End If
End Sub
I really need some help..! I have several forms & several reports in a windows (.aspx) app that I created. The forms have an option to pull data from an outside db, once done, they can edit the form & then click the submit button to save to 1 of the 5 tables I created in SQL. My problem is, we are getting a bunch of duplicate records. There should be 1 row of data (record) per call #.
I have searched & searched & what I found to be the best (with consideration of the user's needs) is if I could have the 'edit' button in the report gridview to redirect to the form page (already created as an input form), only have a couple items changed (such as instead of the submit, to hid that button & enable a 'update' button, IN ADDITION to the form prepopulating with the data (IF any) that's in the table corresponding with that form & report. Although I have created several applications, I am new to hard coding & so 'detailed' guidance is requested. I will GREATLY appreciate any help! This application needs deployed asap so I am really stressing on this one..
Needing Help Desperately..
Kathy
It's actually better to use select and here's why:
Protected Sub MyGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles MyGridView.SelectedIndexChanged
Dim formid As String = gvRequisitonLines.DataKeys(gvRequisitonLines.SelectedRow).Value.ToString()
Reponse.Redirect("~/FormPage.aspx?formid=" & formid)
End Sub
This allows you to get the selected index extremely easily and use it to get the DataKey which you can send as a QueryString parameter to your form page.
Of course this requires that you have your form identifier set as a datakey on the GridView.
So for clarity, your button would have the text "Edit" but the command "Select".
Hey all, i am looking for a way to send a keypress letter/number to a textbox. The reason why i need this is that this textbox is a AutoComplete box that, when the user types, it displays a list of suggestions like google does.
However, for it to work, the user has to click in the box and type something. I can send any number/letter to the box i want using this code:
Private Sub Command_Click()
AutoComplete1.Text = "g"
End Sub
And it does put it into the textbox but it does not trigger the autocomplete list (the list has words like "good","great","pop","test"). Only when i click in the textbox and type "g" is the only time i get the "good","great" suggestions.
Is there a way to trigger this with the code i posted above?
Thanks!
David
Wouldn't
AutoComplete1.SetFocus()
SendKeys("g")
do that?
How about putting the code in the Key_Press event of the textbox instead of click event of the command button?
My guess would be to use Keyup event and fire the code that displays the list of suggestion if it isn't fired by the Keyup event itself
I'm developing an Access 2003 Database that uses a MS SQLServer backend.
I'm trying to do Form Validation and am experiencing some problems.
ValidationRule for each field seems to be ignored
I can't figure out what event I should override to enforce validation without having the database do it. (I'm not against this, it's just unknown to me how I'd catch Error Messages, instead of displaying them to the user)
I've tried getting around number 2 by disallowing closing and enforcing the use of a "Close Button", but the user can side step it by pressing tab, or by pressing the "Next Record" button at the bottom.
Any suggestions would be greatly appreciated.
If you are using the validation rules property, you can catch validation and duplicate key errors, amongst other things, in the Form Error event:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr=2107 Then
MsgBox "Validation error! " & ActiveControl.Name
End If
End Sub
You can enforce the use of your close button with a variable defined at form level and set to false unless your button is clicked.
Option Compare Database
Option Explicit
Public AllowClose As Boolean
Private Sub Form_Load()
AllowClose = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = Not AllowClose
End Sub
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
AllowClose = True
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
From: http://www.tek-tips.com/faqs.cfm?fid=2071
If you give us an example of one of your validation rules, it might help.
However, I've been under the habit of putting validation in Before Update (especially when I've got more complex validation algorithms)
Update:
I did some experimentation and it seems that the validation rule for the field is ONLY checked when you make an update to the field, but not if you are making an update somewhere else on the form, and not when you save the record. So I think your solution is to move validation to Form_BeforeUpdate.
OR you could make the column in the table non-null - which would force the users do something with the field.
OR, if the field must be "Testing", then you could side step the whole thing by setting a default value and locking the field so the user can't change it.
You can hide the navigation buttons by setting the form's Navigation Buttons property to "No." You can also disallow tabbing to a new record by setting the form's Cycle property to "Current Record."
With any nontrival application interface in Access, I usually lock the form down pretty tight and supply my own nav buttons, close button, etc. as needed.