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!

Validation of Invoice reference on data entry. 4

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have become rather confused about validating a field on a data entry form, when the user may divert to another form in the application.

The user is running a form which allows him to enter a (multi-line) purchase invoice and post it to his accounts.

On the header of the form is a text box txtOurRef, which is the invoice reference (usually sequential) which is assigned to that invoice in the purchase ledger. The user may already have a paperwork system where he has already assigned the invoice reference – something like P1056, or (this is a feature of the application) he may just provide a 2-character prefix - say ‘PV’ and the system assigns the next available invoice reference – PV9801 – in the ‘PV’ sequence.

This functionality is provided in the txtOurRef.valid() event. If a full reference is supplied the system checks that this reference has not already been used, and if a 2-character prefix is supplied, the system finds what the next available reference is and displays it (in txtOurRef.value)

However, the user may at any time divert to a different form in the application. He would not do this for frivolous reasons, but he might – for example, if he has not already done so - make an enquiry on the supplier’s account to see what invoices he has already posted.

In this case the txtOurRef.valid() code detects this and abandons the validation. No point in telling the user that he is using an invalid InvRef, when that is what he is about to check up on!

However, when he resumes the original data entry screen it seems to be possible to position anywhere on that form, and so – to bypass the txtOurRef.valid() code.

What do other people feel is the best way of handling this situation (perhaps not ‘Don’t start from there’), but grateful for guidance !

Thanks. Andrew
 
I tend to offer a preliminary number initially, then when the record is saved (at the header level) check again
whether the reference has been taken by another user.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hi,

If txtOurRef gets focus ( GotFocus event) disable all the other controls on the form

Code:
*** This code is in a custom method called "TextBoxesOff" of the ActiveFom - txtInput is the name of my TEXTBOX class

This.SetAll("Enabled", .F., "txtInput")
This.txtOurRef.Enabled = .T.

Asa txtOurRef is validated enable the controls on the form

Code:
*** custom method "TextBoxesOn"

This.SetAll("Enabled", .T., "txtInput")

You may apply the same approach to other controls

hth

marK
 
Andrew, could I check one point. When you say that "txtOurRef.valid() code detects this and abandons the validation", what exactly is it doing? In particular, does txtOurRef.valid() return .T. or .F. in those circumstances?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
... or make the search form modal (see code snippet below)

Code:
**************************************************

PUBLIC goForm1, goForm2

SET CONFIRM ON

goForm2 = CREATEOBJECT("Form2")
goForm1 = CREATEOBJECT("Form1")

goForm1.Show(2)

READ Events

Close all
Clear All
RETURN

**************************************************

DEFINE CLASS form2 AS Form
	Caption = "Check"
	Left = 120
	Height = 480
	Width = 480
	MinHeight = This.Height
	MinWidth = This.Width
	MaxHeight = This.Height
	MaxWidth = This.Width
	
	ADD OBJECT grid1 AS Grid WITH ;
		ColumnCount = -1, ;
		Left = 12, ;
		Top = 48, ;
		Width = 456, ;
		Height = 408, ;
		Anchor = 1 + 2 + 4, ;
		RecordSource = "curTemp", ;
		ReadOnly = .T.
		
	ADD OBJECT lblInfo as label WITH ;
		Autosize = .T., ;
		Top = 24, ;
		Left = 12, ;
		Height = 16, ;
		FontBold = .T., ;
		Caption = "Accepted Values in textbox of Form 1"

ENDDEFINE 

DEFINE CLASS form1 AS Form
	AutoCenter = .T.
	Caption = "Input data"
	Height = 480
	Width = 600
	MinHeight = This.Height
	MinWidth = This.Width
	
	ADD OBJECT lblDataEntry as Label WITH ;
		Top = 12, ;
		Left = 18, ;
		Autosize = .T., ;
		Caption = "Enter data - format [99] "
	
	ADD object txtReference as TextBox WITH ;
		Left = 18, ;
		Top = 36, ;
		Width = 120, ;
		Value = 0, ;
		InputMask = "99"
	
		PROCEDURE txtReference.Valid() 
		
			LOCATE FOR curTemp.F1 = This.Value
				IF FOUND()
					ThisForm.Refresh()
					 
				ELSE
					IF VARTYPE(goForm2) != "O"
						goForm2 = CREATEOBJECT("Form2")
					ENDIF 

					goForm2.Grid1.RecordSource = "curTemp"
					goForm2.Show(1)

					RETURN 0
				ENDIF 
		ENDPROC 

	ADD object txtValue as TextBox WITH ;
		Left = 156, ;
		Top = 36, ;
		Width = 120, ;
		ReadOnly = .T., ;
		ControlSource = "curTemp.f2"

	ADD object txt2ndValue as TextBox WITH ;
		Left = 294, ;
		Top = 36, ;
		Width = 120, ;
		ControlSource = "curTemp.f3"

	PROCEDURE Load 
		CREATE CURSOR curTemp (f1 I AUTOINC NEXTVALUE 1 STEP 1, f2 C(20), f3 C(20))
	
		FOR i = 1 TO 20
			INSERT INTO curTemp (f2, f3) VALUES ("T" + SYS(2015), "")
		ENDFOR
	
		LOCATE 
	ENDPROC 
	
	PROCEDURE Destroy
		ThisForm.Release()
		CLOSE ALL
		Clear Events

	ENDPROC
ENDDEFINE
*********************************************

hth

marK
 
Hi Andrew,

IMHO most important is to decouple the validation field from the rest of the forms inputfields.

One way of handling this could be, to disable all controls (with the execption of the validation textbox) on form start.
Enabling the controls only happens after successful validation.

To make this easier, you could place all controls (that have to be disabled) into a container. That way, only the container has to be switched on/off.
You could even place some code in the forms lostfocus event that initializes the value of the validation textbox if the container is still switched off.

In a rather similar case I also have used a pageframe. Page2 (default) only held a label that tells the user, that the reference field has to be filled correctly and after successful validation I activated Page1 with all the data input. Its more or less the same like disabling the fields.

JM2C


-Tom
 
Thank you all for your prompt and helpful advice.

Thank you Griff. I work with invoice references pretty much as you do, except that I also allow the option (historically) of letting the user enter a full invoice reference if that is the way he works. My problem had been if he works that way, it looks as though a full reference is there on the screen, but I have not saved it to the form property Thisform.cOurRef to which I save txtourref.value.

If he only enters the prefix on the screen (which most of my users do), he would see that I had omitted to generate the full reference and might well realise what I was doing wrong!

And thanks Mark krsr. Your method would work. I had not been disabling the next field (Supplier’s ref as it happens), because I had wrongly thought that (after diverting to another form and returning), VFP would return to txtOurRef.

But mainly Mike L. You have pointed out my blunder! In txtOurRef.valid(), when I allow diversion to another form, I had been returning .T. - confident that, after returning to the invoice form, focus would remain there (because, in my testing, I didn’t see it anywhere else on the screen). I have now changed to RETURN .F. after detecting a click elsewhere on the screen. I can now observe that - after running a creditors’ report or enquiring on the supplier’s account - focus has been forced to remain on txtourref.

Finally Tom, I accept your point of the reliability of having to specifically re-enable the other fields when I am entirely satisfied that I like the look of txtourref.value (or the value I have placed into it following Griff’s technique). Your technique would also solve the problem.

Thank you all for your patience. Andrew M.
 
I also allow the user to specify a prefix, or a whole reference - if they want to, most people don't but sometimes users want to 'fill in gaps' where invoices have been deleted.
Most people cancel invoices rather than reusing the numbers.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top