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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make the number running and displaying on the textbox

Status
Not open for further replies.

millbear

Programmer
May 16, 2002
23
SG
There is a textbox named 'refno' for auto-numbering purpose.
I want to make this textbox visible and display next number when opening the form.

repum - table to store numbers which is next to the existing no in the same line.
rp_num is the name of field in the repum.dbf.

tnfjob - table to store the full details when saving the form.
jt_ref is the field for the "refno number" for each information.

Code:
	if empty(thisform.refno.value)
		select atnfjob
		set order to tnfjobb
		seek alltrim(str(arepnum.rp_num+1))
			do while not eof() .and. jt_refno=alltrim(str(repnum.rp_num+1))
			select arepnum
			do while .not. rlock()
			enddo
			replace rp_num with rp_num + 1
			unlock
			flush
			select atnfjob
			skip
		enddo
	else
		thisform.refno.value
	endif

Above coding seem not working well. The number is not able to run next no and display when opening this form.
Appreciate your kindest help.

Thanks
millbear

Just a Beginner! Need help badly.
 
Millbear:

This is not an answer to your problem.

You may not need to use alltrim() function in index and seek statements. Try viewing a table with/without alltrim() function.

for example,

use NumTable
* Add upto approx. 35 records with values from 1 to 35

index on alltrim(str(NUMFIELD)) to tmp1
browse

and then with

index on str(NUMFIELD) to tmp2
browse


Nasib Kalsi


 
Hi Millbear,

You need to clarify a few points:

1. You say "There is a textbox named 'refno' for auto-numbering purpose." Are you sure that's what you mean? Have you created the textbox and placed it on the form? Or, do you mean that there is field called refno?

2. In your description, you mentioned tables repum and tnfjob. But, in your code, you refer to tables arepnum and atnfjob.

3. What exactly are you trying to achieve? I read your explanation three times, but couldn't understand it. Pleas understand, I'm not saying this to be picky. But if you can't explain a problem clearly, you'll find it very difficult to solve it.

A couple of other points:

- Near the end of your code, you have this line:

thisform.refno.value

As it stands, that line doesn't do anything. It refers to a value of a control on a form, but it doesn't do anything with that value.

- In this particular code, you don't need to explicitly get or release the record lock. VFP will do that automatically when you do the REPLACE.

- Similarly, you don't normally need to do a FLUSH. The command won't do any harm, but it isn't usually needed.

If you could clarify what the problem is, I'm sure you'll get a helpful answer.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

Sorry for not explaining clearly.

1. Yes, I created the textbox and name it as 'refno' for auto-numbering. (See the image)
2. Create another new table 'repnum' to have the next running no for the refno textbox.
rp_num is the field name of the repnum.dbf. So, I put replace rp_num with rp_num + 1..
3. I'm trying to achieve have a next running no. in the textbox when clicking on the tankno textbox.
4. Another problem is that I try to key in new data for the same tank no with different ref.no.(auto-numbering)a few times but overwrite the existing data in the another table (tnfjob) to store all the data of the module. How to write the coding to store a few existing data in next row for same tank no in the tnfjob.dbf.

REMod.JPG


Thanks
millbear

Just a Beginner! Need help badly.
 
Sorry to ask more questions but, to add to what Mike said, the more questions we ask the better the chance of us providing the right answer.

1. How are you generating an autonumber? Are using the AutoIncrement data type?

2. What are you going to do if two people try to use the system at once - will you show them the same "next" number?

3. What are you planning to do if a user abandons the operation? What will you do if one user is adding "10" and another user is adding "11" but the first user decides to abandon "10". Do you need to remember that "10" is now the next available number but that it must be followed by "12"?

My personal preference would be to get rid of the textbox showing the next number - or perhaps to display the words "New Record" until the user decides to save that record.

Geoff Franklin
 
Hi alvechurchdata

1. No, I’m not using AutoIncrement data type. Just normal coding like creating another table that is called repnum and has a field ‘rp_num’ as I mentioned (replace rp_num with rp_num +1 ) earlier. The record is stored in separate table (tnfjob.dbf).
2. You got the point. I overlook it. I think that it is best way to use the Save command button to save the record (Procedure: Click) and then generate the auto-numbering number (let it be 10). Make sure that the number ‘10’ displayed visible after saving and all the record except tankno is cleared when saving.
3. I have created another form to call out the existing ref number and edit/delete the data as well as the ref no. If existing record is deleted, the same user can re-use old number manually. Good idea to search for old numbers which are deleted for re-use without them re-using manually.
4. Regarding to ur personal preference, I think alike but have to meet my boss’s requirement of having the record number for their easy finding against the physical documents.


Thanks
millbear

Just a Beginner! Need help badly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top