1 (edited by lemodizon 2022-05-27 14:02:56)

Topic: Product Code on my textbox (Solved: thanks everyone)

Hi everyone,

I'm trying to insert a product code on each item of my product..  When i click the add button it will go new form and will display prodcode that is available.

i newbie to write a script ...

i tried this script i code but it has error i don't know how to fix it.

procedure frmProd_Add_OnShow (Sender: TObject; Action: string);
begin
            frmProd_Add.txtProdCode.Text:= inttostr(sqlexecute('select max(id) from Products') + 1);

end;

Hope you can guide

thanks in advance...

Post's attachments

Attachment icon ProdCode.JPG 88.76 kb, 65 downloads since 2022-05-20 

-lemodizon

Re: Product Code on my textbox (Solved: thanks everyone)

Here is my practice file of my inventory...

Thanks in advance

Post's attachments

Attachment icon IMS_052122_prodCode.7z 280.36 kb, 134 downloads since 2022-05-20 

-lemodizon

Re: Product Code on my textbox (Solved: thanks everyone)

Hi,
Your database does not contain records. The request returns NULL.
This can be avoided by using IFNULL in the query.

frmProd_Add.txtProdCode.Text := IntToStr(SQLExecute('SELECT IFNULL(MAX(id),0) + 1 FROM Products'));

4 (edited by lemodizon 2022-05-20 07:06:29)

Re: Product Code on my textbox (Solved: thanks everyone)

sparrow wrote:

Hi,
Your database does not contain records. The request returns NULL.
This can be avoided by using IFNULL in the query.

frmProd_Add.txtProdCode.Text := IntToStr(SQLExecute('SELECT IFNULL(MAX(id),0) + 1 FROM Products'));

Hi Sparrow,

thanks for the  response.

i already changed my syntax it works.

but how can i put the prefix "P" to on the id number that will end up like this "P0001"

thanks again

-lemodizon

Re: Product Code on my textbox (Solved: thanks everyone)

frmProd_Add.txtProdCode.Text:= sqlexecute('select "P" || (IFNULL(max(id),0) + 1) from Products');

I think it's time for you to get familiar with SQL.

Re: Product Code on my textbox (Solved: thanks everyone)

sparrow wrote:
frmProd_Add.txtProdCode.Text:= sqlexecute('select "P" || (IFNULL(max(id),0) + 1) from Products');

I think it's time for you to get familiar with SQL.


Hi sparrow,

thanks again. your right..... i'm familiarizing the MVD and little by little i will insert what i learned in sql.

thanks again.

-lemodizon

Re: Product Code on my textbox (Solved: thanks everyone)

Hi,
Rather than use the record-id, it might be better to set up a counter on the relevant table in your database schema and use that (with your 'P' prefix) as the basis for your product code.
You might also want to think about using 'wildcards' in your search and also the incremental search function (see attached).
They're just options to consider but it's as well to be aware of them.
Derek.

Post's attachments

Attachment icon IMS_052122_prodCode2.zip 346.79 kb, 140 downloads since 2022-05-20 

Re: Product Code on my textbox (Solved: thanks everyone)

derek wrote:

Hi,
Rather than use the record-id, it might be better to set up a counter on the relevant table in your database schema and use that (with your 'P' prefix) as the basis for your product code.
You might also want to think about using 'wildcards' in your search and also the incremental search function (see attached).
They're just options to consider but it's as well to be aware of them.
Derek.


Hi Derek,

Thanks for the file.

honestly it's kinda hard on my part coz i don't  know where to start to learn. it's kinda mixed learning MVD interface,sql, database and scripting.

i'm looking for tutorial for script that use MDV platform.

it's hard but i enjoyed to learned in this forum. hope i can create my first inventory application in MDV.


Thank you again.

-lemodizon

9 (edited by sparrow 2022-05-20 16:54:17)

Re: Product Code on my textbox (Solved: thanks everyone)

Hi all,


Start with the simplest, which is what MVD is for.
Creation of the simplest application without a script, SQL, pascal, etc.
The simplest forms, tables, buttons, etc.
Derek tells you this way all the time.
Believe me, a lot can be done without scripts and SQL.
Find examples on the forum, here is an example of the simplest:
http://myvisualdatabase.com/database_ex … ntory.html


This will give you an understanding of how and what works. Other programs can be found on the forum.
Try to add your fields and forms.
From the simplest you will reach more complex programs.
Step by step...
Then a script with the simplest constructions and more... )))

Re: Product Code on my textbox (Solved: thanks everyone)

sparrow wrote:

Hi all,


Start with the simplest, which is what MVD is for.
Creation of the simplest application without a script, SQL, pascal, etc.
The simplest forms, tables, buttons, etc.
Derek tells you this way all the time.
Believe me, a lot can be done without scripts and SQL.
Find examples on the forum, here is an example of the simplest:
http://myvisualdatabase.com/database_ex … ntory.html


This will give you an understanding of how and what works. Other programs can be found on the forum.
Try to add your fields and forms.
From the simplest you will reach more complex programs.
Step by step...
Then a script with the simplest constructions and more... )))



Hi sparrow,

Thanks for this. step by step.

-lemodizon