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

Multiple record

Status
Not open for further replies.

ivatanakoo

IS-IT--Management
Oct 9, 2014
23
PH
how to add multiple record the same record at a time.
append blank
replace name with...
append blank
replace name with...

this doesnt work..
 
Code:
INSERT INTO YourTable (field list here);
SELECT Field list
FROM....


Borislav Borissov
VFP9 SP2, SQL Server
 
i want to add the same data at one time on the same table
 
You appear to have a number of un-answered questions open here at the same time.
This question: Multiple record thread184-1739192
two grid with the same data thread184-1739174​
Methods /properties thread184-1739173​
grid in vfp thread184-1739121​

And you have not replied to any of them that the answers have resolved your problems.

Why don't you work on your questions one at a time until you get an answer that works for you?
After that you would most likely be ready to go on to the next question.

Otherwise we might think that this might be some coursework (homework) project that you are doing.

i want to add the same data at one time on the same table

As Mike indicated above, what specifically does not work with the code you have shown?

Good Luck,
JRB-Bldr
 
I mean i can only add one record at one time in that given code..

i tried to use the for loop but got an error..
sory if the code is not maybe accurate cause i'm new in using loop.
Code:
LOCAL x as Integer 1
	x = thisform.pgfinventory.addinventory.txtQty.Value
	FOR n = 1 TO x
	? n
	SELECT item_table
	APPEND BLANK
		REPLACE unit WITH proper(thisform.pgfinventory.addinventory.cmb_unit.DisplayValue) 
	ENDFOR
 
Well, your code appears to be syntactically correct, but it's not clear what you want to achieve. What the code does is to add x records to the table, where x is the value of your txtQty control. All the records will contain the same data, that is, the value being displayed in the combo. Is that what you want?

Next, it is useless to tell us that you "go an error". You have to tell us what the error is. We need to know the actual message (or error code) and the line in your code that caused the error. I'm sure we've told you this before in other threads.

Off the top of my head, the only thing I can see that might cause an error is the fact that your txtQty might contain a text string rather than a numeric. If it does, that will cause a datatype mis-match error in the line beginning with FOR. To avoid that, you need to convert the string to a numeric, using VAL().

But that's really just a guess. Without more information, you're not going to get a definite answer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Which line is causing the error? Do you know ON ERROR ? It can be used to let VFP call an error handler, if an error happens. If you pass in PROGRAM() and LINENO() you get info about where the error happens.

In this case what could be problematic is as Integer 1, there is no such thing as sepcifying initial value in LOCAL, only the type. Secondly, if you txtQty textbox is not preset to a numeric value the Value is not a numeric but text type. You cant loop FRO n= 1 To "4" for example.

The core code APPEND BLANK/REPLACE repeated several times creates several records. That alone would work. You better INSERT INTO item_table (unit) Values (thisform....DisplayValue). Also make sure the type matches.

VFP is said to be non strict typed, but the nature of it's weak typing doesn't mean you can use strings as numbers or save any variable or property type into any table field type.

Bye, Olaf.
 
Just a general advice, when you're learning new stuff, eg a FOR loop. Simply do a small PRG snippet doing just a loop. Your code involves a form setting the upper bound of the loop and now you have two factors in the code, the form and the code. Start with this to see how things work, then extend that with a form later:

Code:
Create Cursor curTest (iId I, cValue C(254))
For n = 1 to 10
   Append Blank
   Replace iId With n*2-1, cValue With "Hello"
   Insert Into curTest (iId, cValue) Values (n*2, "World")
Endfor
Browse
This is demonstrating the two different ways to add a record, so you get 10*2 records with iid from 1 to 20, alternating between "Hello" and "World" in cValue.

Bye, Olaf.
 
the error is on the declared variable x,
x is not a numeric
 
What we thought.

There are two solutions. Mike already mentioned VAL(), so you could set x = VAL(thisform.pgfinventory.addinventory.txtQty.Value) or you can set the txtQty Value to 1 initially. If a textbox control is initialized to a certain value, it stays that type, so users can only enter other numbers. So if you set the Value to 1 in the Property Window, users can't type in Text into that textbox anymore and you can be sure you have a number in the textbox.value property, unless a user types CTRL+0 and puts in NULL.

A way to assure the users only type in a valid number would be using the VALID event of the textbox. In there check Vartype(This.Value). If that's not what you need tell the user to enter a number and RETURN 0 or .F. to stay in the textbox.

Bye, Olaf.
 
Just to state the obvious, but maybe not so obvious for you: Don't use both solutions, because VAL() of a number errors. Either initialize the txtQty with a number or use VAL().

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top