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!

Losing table focus on PageFrame when clicking between pages 1

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hi

I have several pages on a PageFrame on a form displaying tables in grids such as clients, expenses, hours worked to name a few.

When the forms loads it defaults to Page 1 on the PageFrame showing the client details.

When I click on Page 2 of the PageFrame that displays another grid with the expenses and so forth.

Everything works perfectly until you click on a row in a grid on let's say page2, then clicking back on Page1 when I try to close the form it is showing an error for example: SURNAME not found (which is a field in the client table)

I have error traps to ensure some information is entered for example:

Code:
IF EMPTY(SURNAME)
  nmessage=MESSAGEBOX("Must enter a surname"0+364+0,"System Message")
  thisform.pageframe1.page1.txtsurname.SetFocus
  RETURN 0
ENDIF

I have added the following to the click event on Page1 of the Pageframe to see if that would focus on the table shown on the page:

Code:
thisform.pageframe1.page1.txtsurname.setfocus

I have left the Status Bar on so I can see that when I am clicking on each page and then clicking on a row or field within that row and returning to Page1 it's not changing back to the table I require.

I'm sorry if the explanation is long winded but it's the only way I can describe it.

Any suggestions please guys?


Thank you

Steve
 
A couple of points:

You say you have added code to the click event of Page 1; that code sets focus on the grid. The click event is not the place to do that. You should put the code in the page's Activate event.

You showed the following code:

[tt]thisform.pageframe1.page1.txtsurname.setfocus[/tt]

You implied that the field in question (surname) is a column in the grid. But the above code will set focus to a textbox placed directly on the page. Is that what you expect? And, if so, why exactly are you doing that?

Finally, where are putting your validation code ([tt]IF EMPTY[/tt], etc)? Is it in a Valid event? And, if so, which control? And is the Surname field (in the database table) indeed empty when the form is closed?

The preferred way of doing this sort of thing is to buffer the table, and to do the validation in a Save button, just before you do a TABLEUPDATE(). Is that what you are doing?

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike

The error trapping is within the click event of a command button and that's something I failed to mention.

There is a text field on page 1 of the pageframe hence why I have tried to focus on that.

Please bear with me, I'm fairly new to this.

Thank you

Steve
 
Is the text box on page 1 bound to the Surname field in the table? (In other words, is the Surnmame field the control source of the textbox?)

Also, are you sure you have the correct table selected when the error message appears? The message is saying that you don't have a field named Surname in the currently-selected table. If you are happy that the Surname field does exist, and that you have spelled it correctly, it must be that a different table is selected at that point (or that the table has been closed). You can check for that by looking at ALIAS() at the point that the error message appears.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
when I am clicking on each page and then clicking on a row or field within that row and returning to Page1 it's not changing back to the table I require.

"It" generally won't "switch back". You have to do that. The exception, of course, is a grid. A grid WILL change the currently selected workarea to the grid's controlsource.
 
Code:
IF EMPTY(SURNAME)

I think dan spotted this already, but to stress out the fact: You can only address a field name only, when the current workarea contains such a field. Grids switch workareas to their recordsource (not controlsource, but you see even experts can confuse the one and other, a third one is rowsource, they all have in common to be source of data).

So no matter if you have this in an unbound control like a button or in the valid event of a textbox bound to client.surname, the client table isn't necessarily the current workarea.
Simply address client.surname, if you want to address client.surname, verbose code is always recommended anyway.

So it seems your button is the save button and you check for required values. That's already a good approach. Next problem: I'm not sure if setting focus to some control automatically also activates the page it's on. You'll see for yourself. The solution is quite simple, before you address thisform.pageframe1.page1.txtsurname to set focus to it, you set thisform.pageframe1.activepage=1 or more general thisform.pageframe1.activepage=thisform.pageframe1.page1.pageorder, which would even work if page1 isn't the first page, if you reordered pages via pageorder.

Bye, Olaf.
 
Thank you for the posts guys. Just tried Olafs suggestion and that appears to have resolved my issue. I'll check the whole form and post back with my result

Thank you

Steve
 
My issue was resolved by using Olaf's suggestion.

I added thisform.pageframe1.activepage=1 to the click event for the page concerned on the PageFrame and this is now working.

Thanks to all who posted.

Thank you

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top