Topic: Show ID on form
Hi everyone,
Is there a way to show the record ID number on a form?
Thanks
My Visual Database → General → Show ID on form
Hi everyone,
Is there a way to show the record ID number on a form?
Thanks
Hi Knobby,
You could try something like this (see attached). It's pretty basic but might give you some ideas.
Regards,
Derek.
Knobby, Derek, Another view on it. Since dbitemid/sqlValue is the actual record id from the tablegrid, you could just use this value. No need to do the SqlExecute. Either way works though.
if action <> 'NewRecord' then form2.edit1.text := form1.tablegrid1.sqlValue;
Example:
procedure Form2_OnShow (Sender: string; Action: string);
begin
Form2.Edit1.Value := Form2.ButtonSave.dbGeneralTableId;
end;
Thanks everyone for your replies.
I'm new to MVD and haven't even looked at scripting yet (it may well be beyond me), but will try out your suggestions once I have.
In the meantime I've managed to get the record ID to show on a table grid so may leave it at that for now.
Hi Knobby, EHW,
If you don't want to use a script to show the record id on an edit form, the only other way I can think of is to use a calculated field (however, this doesn't let you see what the record id WOULD be when adding a record unlike my previous example - so this is only going to be for existing records).
Please have a look at the attached project, specifically at the data structure and how I've set up the calculated field.
Regards,
Derek.
Thanks again.
I need to do this as it's a requirement for the task (i.e. show the record ID on the form), so I'm back at it again.
Unfortunately I can't seem to get any of these ideas to work.
Derek - I ran your project and initially it worked, but for some reason it now doesn't show the record ID on the form; just a grey box. It does show the record ID in the grid table after the record has been saved.
I tried the other scripts but keep getting errors such as " ; expected at 5.1" which, if I put in a ";" gives me " begin expected at 6.1 "
I then tried creating a simple table to test these on but can't save any records as I get a message saying "No such table" although the table exists.
Hi Knobby,
Is there any chance you can upload your project and then someone will no doubt take a look at it (that's when you end up with 5 different solutions because we all have our own ways of doing things!).
But from what you've described, it sounds like you're missing an 'end;' at the end of one of your procedures; just putting a ';' on its own will simply move the error down to the next line. Typically, the format for any procedure is
procedure xyz;
begin
abc
abc
end;
This would account for both the error message you get and the grey box showing.
Derek.
Ok, here's the project. I tried using the script provided by Dmitri, but the same thing happens if I copy your script into my project.
Hi Knobby,
Attached are two versions of your project.
Version 1 has no script and uses a calculated field to display the ID on frmclient and is the most straightforward way to do it.
Version 2 uses a script; with this version, you can also see what the next available ID is when you are adding a record.
Your script didn't work for 2 main reasons
1. it was missing a final 'begin end.'. have a look at the script in Version 2 and you'll see.
2. every procedure in a script needs to be associated with an 'event'. If you look at the attached screenshot (knobby1.jpg) for frmclient, you will see the object inspector has 2 tabs - 'properties' and 'events' (if scripting is turned off, you will only see 'properties'). In your example, an 'on show' event has been created (frmclient_onshow) and this is how the association is made to the frmclient_onshow procedure in the script.
I appreciate it probably sounds like a lot of work but once you are familiar with it, it's very straightforward.
But there's a lot you can do with basic MVD and I'm sure there are some of us who never bother with scripting at all.
Regards,
Derek.
Thanks Derek, you're a star.
The version with the script does exactly what I need, and I now understand why I was getting errors about ";", etc.
Once I've deleted the test records, is there a way to reset the record number to start again from 1?
Hi Knobby,
Once you've done all your testing and are ready to start using it 'for real', the easiest way is to go into the directory where your program is stored, locate the file where your actual data is held (typically sqlite.db) and delete it. The next time you run your program, sqlite.db will be recreated and the record numbers will have been reset (please note that ALL your data will be deleted).
Regards,
Derek.
My Visual Database → General → Show ID on form
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi