Hi Jim,Knightlite wrote:Hi marksmithhfx,
Its really different than what I was doing, so it looks like I was doing everything wrong. It will take me a few days to figure out what you did, but I really appreciate the help.
Jim
I would not say that what you were doing is wrong. THe update and display routines are very different from what you were doing because... I am not giving you code to do it. I am giving you code that writes the code to do it. That is a very different approach. Background: I learned very quickly that I hated writing code to write LC fields to database fields. Its messy, it is full of weird complexity, and it is prone to error. I was spending more time debugging the stuff I was writing than writing it. I confess, it is one of my weaknesses (ask anyone here!): I am terrible at syntax. So what I did is write some simple little 16 line routines that will write out all the LC/SQL code I need to read and write fields to/from databases. Basically the "update" routine is my "write2db" code, and the "display" routine is my "read_from_db" routine. I actually take a slightly different tack in the read-from code and put the record into a recordset just so I can take advantage of reading the values out of the record set by field name (hence the requirement of correspondence between field names on the card and field names in the database). If you would like to see how the write routine is writing the sql code there is a line you can uncomment that will put the sql out to the msg box:
-- put return & tCmd after msg -- uncomment this line if you want to see what tCmd looks like
Now, this is just one approach. Basically I've done it this way to avoid having to hand code, as much as possible, any SQL. THere are many other perfectly legitimate approaches to doing this. However, even if this does not become your preferred approach you'll probably pick up a trick or two by reading and understanding this approach. Also, the approach I took is not perfect... I had trouble seeing how I could delete records and still satisfy your need to move backwards and forwards in the file. I would need to rethink how to do that in order to properly delete records. So, ideas offered by others here might provide a better solution. At the very least, it should run reliably and should help get you started. You can tinker with it and modify it from its current form and refine it until you get it working the way you want.
If I can answer any questions, don't hesitate to ask.
-- Mark
PS I don't know if RR archives the RevUP newsletters but if you can get your hands on issues 131, 132 and 133 I wrote some articles explaining the approach and providing sample code. The first article (131) describes in graphic detail some of the nightmares I was facing that led me to create this approach. Like I said, it is probably not for everyone but the articles might help to explain it a bit more.