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!

Adding an Edit button in the main form as the other buttons

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi,
This is a problem i always have, i created a data entry application where users enter their user ID, JOB# they are working on, the time they were working in that job and the description of the job, so i have no problem with that so the form will have some buttons that will allow you to ADD, DELETE, CANCEL, SAVE and CLOSE, to close the form and comeback to the menu, the problem i have is that i don't have an Edit button cause i have not figured out how can add this to the form and be able to edit the record i want in that form, i think the approach i could take should be something like:

1- I will have to create an Edit button in the form where i have the rest of the button
2- Then when the user click the Edit, open another form with a textbox to search by the Employee ID#
3- Then show in a grid or ListBox the Job#s he has been working, then select the one he needs to edit
4- Then show that record into the main form where i have all the buttons
5- now be able to allow all the texrboxes to be editable, like the Time, Job# or any other values shown in the other textboxes.
6 save those changes
any suggestion, this is a multiuser application i did in vfp 5.0 a few years ago, Ok let me clarify that when the users add a new entry and save it they can scroll thru the records in that form using the First, Next and Last buttons that i created in that form but these textboxes are read only once the data had been saved so there is not way to change anything in that form
Thanks
Ernesto
 
the problem i have is that i don't have an Edit button cause i have not figured out how can add this to the form

Have your VFP Form open in the Development Mode
From your Top-level VFP Menu select View - Form Controls Toolbar
From that tool bar select a Button and drag it onto your Form.

Now modify the new Button's Properties to meet your needs.
And write code into the Button's Click Method to meet your needs.

For example:
Code:
* --- Then when the user click the Edit, open another form with a textbox to search by the Employee ID# ---
DO FORM "FindID"  && Make a Form to do this named "FindID" (or some other name)
 * --- When you return from that secondary Form use values in first form as needed ---
*  <and so on>
*  ETC.
*


Good Luck,
JRB-Bldr

 
JRB-Bldr,

1- there is only one table involved here, second this is in a multiuser enviroment, third i need to display the record founded in the main form and be able to edit, while still other users can have access from other computers to add records to the same table

2-What is the mechanics to comeback to the main form with the values found for that specific record(let say if i displayed them in a grid),

3-let say that i will create a form with a textbox to input the Emplid#, then once i clicked a command button named "search" with some code into click properties, that will find that employeed id and then display all the records related with his id# starting from the bottom(cause normally if a record needs to be edit most likely is one of the lattes entries), i guess i should display them into a grid, then i will need the option to double click in that grid the record i need to edit(or the one is needed to be sent back to the main form) then a way to comeback to the main form with that record displayed, with all the textform enabled to be edit, then save the changes.
Do you think this could be a route to accomplish this, i just need to know how can i pass to the main form the values selected from the grid, and of course in the grid the action that allow me to select the record
Thanks a lot
 
Adding an Edit button in the main form
and
the problem i have is that i don't have an Edit button cause i have not figured out how can add this to the form
and
there is only one table involved here, second this is in a multiuser enviroment, third i need to display the record founded in the main form and be able to edit, while still other users can have access from other computers to add records to the same table

Your 3rd statement has nothing to do with the first two statements.
You can easily Add an Edit button and call a 2nd form with code from within that button's Click Method
And, upon returning from the Secondary Form you can easily use the ID found there within the first form.

It sounds like your issue is VERY different than you opened your posting with.

VFP, is by default, a multi-user environment.

And it will inherently apply Record-level locking to a data table.
But, if you feel it is necessary, you CAN add additional code to better ENFORCE the access to individual records.

There are multiple ways to 'pass' a variable to the 2nd Form in such a manner that the return value can then be utilized in the Primary Form. Think of the 2nd Form as a form of FUNCTION (a UDF).

Rather than going through all of them, you can use the Search utility in this forum and look for: pass to form

How you display your data is totally dependent on the amount of data needed to be displayed and on your specific needs.

If for a given EmplID you have a good number of records to display - a Grid might be a good choice. Along with individual TextBoxes utilized for Editing individual record values.

But if you only have single records of data to deal with you most likely do not need the Grid.

But that is your choice.
Since many of these questions are Really Basic design questions you might want to spend some time with the free on-line VFP tutorial videos at:

Good Luck,
JRB-Bldr
 
JRB-Bldr,
Thanks a lot i will take a look to the search for "pass to form"
 
Hi,
I did this in VFP 5.0
I am having a little issues with the grid displaying the data i want, actually when i typed in my main form text search box and click on the search button this will open another form with a grid to display all the records that match whatever i typed in the textbox and until this point everything is ok but once i select on that record or row with a mouse click to Edit on that grid then it fills up the grid with more records(the pointer does not move from that record wich is fine) that are similar of the one i typed but not exactly the same but the begining characters of the records displayed are close to the one i found, and that makes sense cause the table is ordered by Vendpartno and some of them are similar but not exactly the same and i don't need them to be displayed, what it does not make sense why will display more than the records i asked for and why not just simply the records that just matched exactly the Vendpartno as the one i just inputed into the textbox, i will insert here some code and the properties, any suggestions will be very appreciated to resolve this problem.

In My startup prg file i have "SET MULTILOCK ON" and this form is called via a menu mpr

A form named fvpart_2.scx
in the form activate event i have
thisForm.txtinput.Setfocus() && this where i will type the Vendpartno
thisForm.refresh

in the data environment, i have a free table named potran04.dbf
datasesion = default datasession

in the form load event i have
PUBLIC p_art_2, emp_ty

the textbox property controlsource = p_art_2
the " " " " Gotfocus the code is as below
p_art_2=""
emp_ty=.f.

in the textbox property interactiveChange
PUBLIC nLenp_art_2
IF NOT EMPTY(THIS.VALUE)
emp_ty=.f.
p_art_2 = ALLTRIM(thisform.txtinput.value)
nLenp_art_2= len(ALLTRIM(p_art_2)) && to know how long is the string new 03/08/2013
ENDIF

textbox property LostFocus
if empty(this.value)
emp_ty=.t.
wait window [You need to enter a Part No to search, TRY AGAIN] NOWAIT
thisform.txtinput.value=""
THISFORM.REFRESH
endif

The command button named "SEARCH"
In the click event the code
public vp
set order to vpartno
set filter to
go top
if emp_ty
thisForm.txtinput.Setfocus()
thisform.refresh
thisform.txtinput.value=""
retur 0
endif
SEEK ALLTRIM(p_art_2)
if found()
store vpartno to vp
vp=alltrim(vp)
rlock()
WAit window [Please wait while searching .....] nowait
SET KEY TO LEFT(ALLTRIM(VP),nLenp_art_2)
do form mgri_2
thisform.refresh
set key to
unlock all
thisform.txtinput.value=""
THISFORM.REFRESH
go top
ELSE
wait window [VPARTNO NO FOUND TRY AGAIN] NOWAIT
thisform.refresh
thisform.txtinput.value=""
GO TOP
ENDIF
THISFORM.REFRESH

An Exit button, in the click Event code
emp_ty=.f.
THISFORM.REFRESH
THISFORM.release
select potran04
set order to vpartno
go top

the second form that has the grid on it is named mgri_2.scx
data env. for the form is the same table POTRAN04.DBF
Datasessinon: default data session
Bufermode= 2 Optimistic

on the Grid1 the RecordSource=POTRAN04
" " " " " " RecordSource Type= Alias
on the Grid1 MouseMove event i have
LPARAMETERS nButton, nShift, nXCoord, nYCoord
PUBLIC rec
store recno() to rec && i did this with the purpose when i move the mouse to that record to record the; recno() to rec, then in case i need to press the Cancel Button , i can issue the tablerevert()

only text1 in column5 and text1 in column6 are Readonly =.f., cause are the only cells i want to edit in this case, the others one i have then as readonly=.t.
in the valid event of column5 text1, i have this code
V_re=.T.
IF this.Value<=DATE()
Messagebox("Date must be more than today's date")
RETURN 0
ENDIF
nAnswer = MESSAGEBOX("IS THIS DATE CORRECT ? Press Yes to Continue or NO to Reenter it " , 4)

DO CASE
CASE nAnswer = 6 && for Yes answer
V_ret=.F.
CASE nAnswer = 7 && for No answer
V_ret=.T.
retu 0
endcase

Ok now the SAVE, CANCEL AND EXIT Commands Button

The Save command is not cause i added a record, it is just to save the information i added into to two specific fields from an existing record i selected

Save command Click code
PUBLIC rec
sele potran04
set order to vpartno
IF RLOCK()
store vpartno to vpart
store recno() to rec
unlock all
goto rec
endif
tableupdate()
THISFORM.REFRESH
wait window [THIS RECORD HAS BEEN UPDATED...] TIMEOUT 4

Cancel Command, just for the case after i typed and before i press the Save i can revert the entries on those two fields/Colums in that grid
Code
goto rec
tablerevert()
THISFORM.REFRESH
wait window [THIS RECORD HAS NOT BEEN UPDATED...] TIMEOUT 4
i am able to go to that record to revert cause i declared a Public rec in the MouseMove event

Exit command Click Code
V_ret=.F.
go top
THISFORM.REFRESH
THISFORM.RELEASE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top