1

Konu: Can't get "Append blank" to work

Hello:

I have Locator Grid (FoxyClasses) and text/edit boxes in the same form. I have a button "New" on the form, and the code is

Visual Fox Pro
THISFORM.btn_new()


In form method btn_new, I have

Visual Fox Pro
APPEND BLANK


However, I cannot make the blank record to show up on the form. I have tried creating another form and doing the same there, but it seems as if the grid is controlling what shows after I do "APPEND BLANK".

How do I get this to work?

Regards,

Hans L

2

Re: Can't get "Append blank" to work

1) Before "Append blank", select the alias into which you would append. Then for it to show up, be sure the textboxes are bound to that alias' fields.
2) Do not use "append blank". It doesn't lock the record appended and you may unintentionally end editing another record in a multiuser environment. Prefer "insert into".

Here is a sample with locatorgrid:

Visual Fox Pro
Public oForm

oForm = Createobject('SampleForm')
oForm.Show()
 
Define Class SampleForm As Form
  DataSession=2
  Height=600
  Width=800
  EditMode=.F.
 
  Add Object locgrdCustomer As locGrid With ;
    cSQL='* from customer',;
    Height=300, ;
    FollowTable='Customer', FollowField='cust_id',FollowTag='cust_id'
  Add Object btnNew As CommandButton With Top=310, Height=50, Width=100,Caption='New'
  Add Object btnEdit As CommandButton With Top=310, Height=50, Width=100,Left=120,Caption='Edit'
 
  Add Object cntCustomer As myCustomer With Top = 365, Left = 10, Width = 120
 
  Procedure Load
    Set Multilocks On
    Use (_samples+'data\customer')
    CursorSetProp("Buffering",5,'Customer')
  Endproc
 
  Procedure btnNew.Click
    Thisform.AddProperty('CurrentCustomerKey', Customer.Cust_id) && save current key
    If Thisform.EditMode && was adding/editing - save
      Thisform.SaveCustomer()
    Else && Insert and go in editMode
      Insert Into Customer (Cust_id) Values (Right(Sys(2015),6))
    Endif
    Thisform.EditMode = !Thisform.EditMode
  Endproc
 
  Procedure btnEdit.Click
    If Thisform.EditMode && was adding/editing - Revert
      Thisform.RevertCustomer()
    Else && go in editMode
      * Nothing here - just need to switch to editmode
    Endif
    Thisform.EditMode = !Thisform.EditMode
    Thisform.AddProperty('CurrentCustomerKey', Customer.Cust_id) && save current key
  Endproc
 
  Procedure SaveCustomer
    Local lcKey
    lcKey = Customer.Cust_id && newly inserted key
    Tableupdate(2,.T.,'Customer')
    Thisform.locgrdCustomer.Reload()
    Select (Thisform.locgrdCustomer.RecordSource)
    Locate For Cust_id = m.lcKey
 
    Thisform.locgrdCustomer.SetFocus()
    Thisform.locgrdCustomer.AfterRowColChange(1)
  Endproc
 
  Procedure RevertCustomer
    Tablerevert(.T.,'Customer')
    Select (Thisform.locgrdCustomer.RecordSource)
    Locate For Cust_id = Thisform.CurrentCustomerKey
    Thisform.locgrdCustomer.SetFocus()
    Thisform.locgrdCustomer.AfterRowColChange(1)
  Endproc
 
  Procedure EditMode_Assign(vNewVal) && insert/save
    This.EditMode = m.vNewVal
    This.cntCustomer.SetAll('Enabled', This.EditMode) && enable/disable textboxes
    This.locgrdCustomer.Enabled = !This.EditMode && enable/Disable locator grid
    This.btnNew.Caption=Iif(This.EditMode,'Save','New')
    This.btnEdit.Caption=Iif(This.EditMode,'Revert','Edit')
    Thisform.Refresh()
  Endproc
 
  Procedure Init
    This.EditMode = .F.
  Endproc
Enddefine
 
Define Class locGrid As LocatorGrid Of 'd:\FoxyClasses\Classes\grids.vcx'
Enddefine
 
Define Class myCustomer As Container
  Height=140
  Add Object txtCustID As TextBox With Top=10, Left=10,Height=30, Width=100, ;
    ControlSource='Customer.cust_id'
  Add Object txtCompany As TextBox With Top=50, Left=10,Height=30, Width=100, ;
    ControlSource='Customer.company'
  Add Object txtContact As TextBox With Top=90, Left=10,Height=30, Width=100, ;
    ControlSource='Customer.contact'
Enddefine

3

Re: Can't get "Append blank" to work

Nice weekend reading :-)

Seriously, thank you very much.

Hans L

4

Re: Can't get "Append blank" to work

Trying to use INSERT INTO using the information above. Great stuff.

Now, a detail: I am trying to insert "INSERT INTO tbtewese" into a form's method. Seems not to work (syntax error). So, after having searched on the Internet without success, my questions are:

-  where can one read about what can and cannot be put into a form's method?

-  is there a rule one can apply to decide what can go into a form's method and what cannot?

Regards,

Hans L

5

Re: Can't get "Append blank" to work

I am sorry I don't understand the question. "Insert into" is just fine in a form method. Maybe I should need to see your exact command, where it is written, what is the error message etc.

6

Re: Can't get "Append blank" to work

I am inserting the code below via the Program Manager into a form's custom method:

Visual Fox Pro
INSERT INTO tbtewese


When I try to save, I get the error message

------------------------------------
[FoxPro icon]  Compile

!  Syntax error

Cancel   Ignore   Ignore all
------------------------------------

Regards,

Hans L

7

Re: Can't get "Append blank" to work

Visual Fox Pro
INSERT INTO tbtewese (field1,field2,field3) values(value1,value2,value3)

8

Re: Can't get "Append blank" to work

Thank you, Soykan. that worked. I thought all fields and values were optional, but I see now that you must at least have "Values ("value")" in there. Damn, one might think that I am blind.

Now, however,, since my key field is Integer (AutoInc), I do not want to add any values, just create an empty record. How is that done?

Regards,

Hans L

9

Re: Can't get "Append blank" to work

Syntax Could be

Visual Fox Pro
INSERT INTO tbtewese () values(value1,value2,value3)

BTW default fields automatically inserting to the table let us see in example

Visual Fox Pro
CREATE CURSOR test(pID I autoinc,fname c(10),age I)

 
INSERT INTO test(fname,age) values("soykan",40)
INSERT INTO test(fname,age) values("hans",40)
BROWSE

as you'll see for pID we dont need to put expr. left and right side at insert into ....

HTH

10 Son düzenleyen, Hans L (18.02.2011 23:58:06)

Re: Can't get "Append blank" to work

Okay, I will check the automatic inserting code in a while (I am sure it works :-)

However, doesn't code

Visual Fox Pro
INSERT INTO tbtewese () values(value1,value2,value3)

mean that values 1-3 are inserted in the first three fields in my table?

I want all empty fields so that I can add my own data in the new record. Perhaps I can have a field that is only used to insert some data that will never be used, e.g.

Visual Fox Pro
INSERT INTO tbtewese () values("Never to be seen or used")

Hans L

11

Re: Can't get "Append blank" to work

Visual Fox Pro
INSERT INTO tbtewese () values(value1,value2,value3)

above codes mean inserting val1...3 except default valued columns eg. autoinc or assigned from stored procedure

12

Re: Can't get "Append blank" to work

Okay, I understand, Soykan.

Thank you very much!

Hans L

13

Re: Can't get "Append blank" to work

I just tried the code

Visual Fox Pro
CREATE CURSOR test(pID I autoinc,fname c(10),age I)

INSERT INTO test(fname,age) values("soykan",40)
INSERT INTO test(fname,age) values("hans",40)
BROWSE

and it did work, of course.

And I thank you for your kindness of making me 40 years young. ) (I will be 69 in July, but a very young 69, almost 40, as a matter of fact :-)

Hans L

14

Re: Can't get "Append blank" to work

glad to see you 40 years old smile

15

Re: Can't get "Append blank" to work

For an 'empty' insertion just pick up a field that you can provide an empty value. ie: Suppose firstName field exists and is character (naturally:) :

Visual Fox Pro
insert into myTable (firstName) values ('')

Soykan,
I wouldn't suggest using:

Visual Fox Pro
insert into myTable () values (v1,v2,v3)

because then code become dependent on the physical order of columns which may change one day.

16

Re: Can't get "Append blank" to work

Thanks, Cetin. Only problem would be if "firstName" was ever changed (probably only if the user was allowed to change it). Could be safer to have a field that is never shown, and always using the same name for it (e.g. "insertintofield").

Regards,

Hans L

17

Re: Can't get "Append blank" to work

That is not a problem. With append blank "" would be assigned to that field and we are doing the same thing with insert.