Hello all,
I have been having trouble with my search form off and on. It will work for a while, and then the next time I try it, it fails, telling me that "Enter must begin first". Each time it fails, I tinker around with the code, trying a slightly different method of achieving the same goal. Eventually it will start working again, but not forever! I'm not too proud of this block of code; it is quite messy since I keep trying new things. Also, one of my biggest successes seems to come from doing something which is not the "standard" way. I have pasted a section of my code here for you guys to look at, but I will now try to explain some of it to you.
This section of code is part of an OnClick event of a button. Earlier in the script, I queried an external SQL database for some information. Now I want to store that information in the table on which this form is built. It seems to me that the best way of accomplishing this is to zap the table (empty it) and enter in the new data. At the end of this code, I show a browse (called SearchResults) which is linked to the Search table. The problems I am having seem to revolve around entering in the data.
I have tried using Table.Open, Table.Get, and Table.Current. I have tried using Enter and Change.
I am sure that much of my code is quite useless and redundant; I was just trying to throw in every check and safety I could think of.
The most interesting lines of code (in my opinion) are Blank.Activate() and ShipmentNumber.Activate(). I am basically using inherent code built into the form in order to achieve my goals. The Blank field is tied to a field in the Search table, so entering that field (I think) puts the table into enter mode. The ShipmentNumber field is tied to a variable, not the Search table, so entering it from the Blank field (I think) saves the record that was being entered, and takes the table out of enter mode. Another possibility is that because we cycled through every field on the form (Think of Monopoly - Advance to a space half way across the board, then advance to your original space; you went one full circle), it saved the current row and moved on to the next row of the table. I don't really know what is happening when I do this or why it works, but it magically helps me fulfill my goals.
Here is my code as I currently have it. Commented code is present to show things I've tried, and to easily switch between different ideas:
If anyone can help me find a better way to accomplish my task, I would really appreciate it!
Jacob Hapner
IT Intern
Hyndman Industrial Products, Inc.
I have been having trouble with my search form off and on. It will work for a while, and then the next time I try it, it fails, telling me that "Enter must begin first". Each time it fails, I tinker around with the code, trying a slightly different method of achieving the same goal. Eventually it will start working again, but not forever! I'm not too proud of this block of code; it is quite messy since I keep trying new things. Also, one of my biggest successes seems to come from doing something which is not the "standard" way. I have pasted a section of my code here for you guys to look at, but I will now try to explain some of it to you.
This section of code is part of an OnClick event of a button. Earlier in the script, I queried an external SQL database for some information. Now I want to store that information in the table on which this form is built. It seems to me that the best way of accomplishing this is to zap the table (empty it) and enter in the new data. At the end of this code, I show a browse (called SearchResults) which is linked to the Search table. The problems I am having seem to revolve around entering in the data.
I have tried using Table.Open, Table.Get, and Table.Current. I have tried using Enter and Change.
I am sure that much of my code is quite useless and redundant; I was just trying to throw in every check and safety I could think of.
The most interesting lines of code (in my opinion) are Blank.Activate() and ShipmentNumber.Activate(). I am basically using inherent code built into the form in order to achieve my goals. The Blank field is tied to a field in the Search table, so entering that field (I think) puts the table into enter mode. The ShipmentNumber field is tied to a variable, not the Search table, so entering it from the Blank field (I think) saves the record that was being entered, and takes the table out of enter mode. Another possibility is that because we cycled through every field on the form (Think of Monopoly - Advance to a space half way across the board, then advance to your original space; you went one full circle), it saved the current row and moved on to the next row of the table. I don't really know what is happening when I do this or why it works, but it magically helps me fulfill my goals.
Here is my code as I currently have it. Commented code is present to show things I've tried, and to easily switch between different ideas:
Code:
RS = LabelDatabase.ResultSet dim SearchTable as P 'SearchTable = Table.Current() SearchTable = Table.Get("Search") if SearchTable.Mode_Get() = 1 then SearchTable.Change_End(.t.) xbasic_wait_for_idle() elseif SearchTable.Mode_Get() = 2 then SearchTable.Enter_End(.t.) xbasic_wait_for_idle() end if SearchTable.Zap(.t.) 'SearchTable.Fetch_First() 'dim CurrentRecord as N while RS.NextRow() ' CurrentRecord = SearchTable.RecNo() if SearchTable.Mode_Get() = 0 then SearchTable.Fetch_Last() SearchTable.Enter_Begin(.t.) elseif SearchTable.Mode_Get() = 1 then SearchTable.Change_End(.t.) xbasic_wait_for_idle() SearchTable.Enter_Begin(.t.) xbasic_wait_for_idle() end if ' SearchTable.Enter_Begin(.t.) ' SearchTable.Change_Begin(.t.) Blank.Activate() SearchTable.ShipmentNumber = RS.Data("ShipmentNumber") SearchTable.SalesOrderNumber = RS.Data("SalesOrderNumber") SearchTable.JobNumber = RS.Data("JobNumber") SearchTable.UserID = RS.Data("UserID") SearchTable.DateModified = RS.Data("Date") ShipmentNumber.Activate() ' SearchTable.Enter_End(.t., .t.) ' SearchTable.Change_End(.t., .t.) if SearchTable.Mode_Get() = 1 then SearchTable.Change_End(.t.) xbasic_wait_for_idle() elseif SearchTable.Mode_Get() = 2 then SearchTable.Enter_End(.t.) xbasic_wait_for_idle() end if ' SearchTable.Fetch_GoTo(CurrentRecord) ' SearchTable.Fetch_Next() end while SearchResults.Show()
Jacob Hapner
IT Intern
Hyndman Industrial Products, Inc.
Comment