Using default data in forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a form with command buttons that activates some codes to set a text
box with a certain price. This "price" text box can be changed to any price
the user wants to enter but the command buttons facilitates the convenience
of quickly choosing some default prices instead of entering it one by one for
a "what-if" scenario.

Everything is working great so far ... but of course ... now I want to
change something that works by adding more flexibility to the form. That is
to say ... I want those default command buttons to be changeable as well. I
would like to do this by having the code take the default price from a
default table instead of being hard coded.

The only code I have currently for my click event is:

Me.PDM.Value = 252.36

I created TableDefault with a record key="M" that can give me DefDM that
contains 252.36. The same record will give me the default for other command
buttons as well.

The form's record source is unrelated to the default table. I know how to
update a table from a form but I don't know how to assign another table's
data to a variable to be used by the form.

I hope this is clearer than mud :-}

Please help!
 
Your code should be something like:

Me.PDM = DLookup("[DefDM]","TableDefault","[ID]='M'")

where I have assumed the table name to be TableDefault, the price field
DefDM and the primary key field (which you call reord key below) ID.
Change whatever is different to the actual name, and make sure you don't
change the syntax.

Note also I have removed the .Value property reference which is
redundant, being the default value referenced anyway.

HTH,
Nikos
 
It works like a charm ... thanks a million!

Funny how easy it is once you see how it's done!

To assign several variables from the same record ... do I have to create as
many lines as I have fields or is there a more efficient way in doing it?

i.e.
Me.PDM1 = DLookup("[DefDM1]", "Master", "[DefKey]='M'")
Me.PDM2 = DLookup("[DefDM2]", "Master", "[DefKey]='M'")
Me.PDM3 = DLookup("[DefDM3]", "Master", "[DefKey]='M'")
....


Nikos Yannacopoulos said:
Your code should be something like:

Me.PDM = DLookup("[DefDM]","TableDefault","[ID]='M'")

where I have assumed the table name to be TableDefault, the price field
DefDM and the primary key field (which you call reord key below) ID.
Change whatever is different to the actual name, and make sure you don't
change the syntax.

Note also I have removed the .Value property reference which is
redundant, being the default value referenced anyway.

HTH,
Nikos
Hello,

I have a form with command buttons that activates some codes to set a text
box with a certain price. This "price" text box can be changed to any price
the user wants to enter but the command buttons facilitates the convenience
of quickly choosing some default prices instead of entering it one by one for
a "what-if" scenario.

Everything is working great so far ... but of course ... now I want to
change something that works by adding more flexibility to the form. That is
to say ... I want those default command buttons to be changeable as well. I
would like to do this by having the code take the default price from a
default table instead of being hard coded.

The only code I have currently for my click event is:

Me.PDM.Value = 252.36

I created TableDefault with a record key="M" that can give me DefDM that
contains 252.36. The same record will give me the default for other command
buttons as well.

The form's record source is unrelated to the default table. I know how to
update a table from a form but I don't know how to assign another table's
data to a variable to be used by the form.

I hope this is clearer than mud :-}

Please help!
 
Sequential numbering makes it possible to:

For i = 1 to 10 '(or whatever number)
ctl = "PDM" & i
Me.Controls(ctl) = DLookup("[DefDM" & i & "]", "Master",
"[DefKey]='M'")
Next

watch out for wrapping in the post, the DLookup expression must be in
one line!

HTH,
Nikos
It works like a charm ... thanks a million!

Funny how easy it is once you see how it's done!

To assign several variables from the same record ... do I have to create as
many lines as I have fields or is there a more efficient way in doing it?

i.e.
Me.PDM1 = DLookup("[DefDM1]", "Master", "[DefKey]='M'")
Me.PDM2 = DLookup("[DefDM2]", "Master", "[DefKey]='M'")
Me.PDM3 = DLookup("[DefDM3]", "Master", "[DefKey]='M'")
...


:

Your code should be something like:

Me.PDM = DLookup("[DefDM]","TableDefault","[ID]='M'")

where I have assumed the table name to be TableDefault, the price field
DefDM and the primary key field (which you call reord key below) ID.
Change whatever is different to the actual name, and make sure you don't
change the syntax.

Note also I have removed the .Value property reference which is
redundant, being the default value referenced anyway.

HTH,
Nikos
Hello,

I have a form with command buttons that activates some codes to set a text
box with a certain price. This "price" text box can be changed to any price
the user wants to enter but the command buttons facilitates the convenience
of quickly choosing some default prices instead of entering it one by one for
a "what-if" scenario.

Everything is working great so far ... but of course ... now I want to
change something that works by adding more flexibility to the form. That is
to say ... I want those default command buttons to be changeable as well. I
would like to do this by having the code take the default price from a
default table instead of being hard coded.

The only code I have currently for my click event is:

Me.PDM.Value = 252.36

I created TableDefault with a record key="M" that can give me DefDM that
contains 252.36. The same record will give me the default for other command
buttons as well.

The form's record source is unrelated to the default table. I know how to
update a table from a form but I don't know how to assign another table's
data to a variable to be used by the form.

I hope this is clearer than mud :-}

Please help!
 
Got it Niko ... thanks!

I was hoping it could be done with a select stmt to deal with the unnumbered
fields.

mgp

Nikos Yannacopoulos said:
Sequential numbering makes it possible to:

For i = 1 to 10 '(or whatever number)
ctl = "PDM" & i
Me.Controls(ctl) = DLookup("[DefDM" & i & "]", "Master",
"[DefKey]='M'")
Next

watch out for wrapping in the post, the DLookup expression must be in
one line!

HTH,
Nikos
It works like a charm ... thanks a million!

Funny how easy it is once you see how it's done!

To assign several variables from the same record ... do I have to create as
many lines as I have fields or is there a more efficient way in doing it?

i.e.
Me.PDM1 = DLookup("[DefDM1]", "Master", "[DefKey]='M'")
Me.PDM2 = DLookup("[DefDM2]", "Master", "[DefKey]='M'")
Me.PDM3 = DLookup("[DefDM3]", "Master", "[DefKey]='M'")
...


:

Your code should be something like:

Me.PDM = DLookup("[DefDM]","TableDefault","[ID]='M'")

where I have assumed the table name to be TableDefault, the price field
DefDM and the primary key field (which you call reord key below) ID.
Change whatever is different to the actual name, and make sure you don't
change the syntax.

Note also I have removed the .Value property reference which is
redundant, being the default value referenced anyway.

HTH,
Nikos

mgp wrote:

Hello,

I have a form with command buttons that activates some codes to set a text
box with a certain price. This "price" text box can be changed to any price
the user wants to enter but the command buttons facilitates the convenience
of quickly choosing some default prices instead of entering it one by one for
a "what-if" scenario.

Everything is working great so far ... but of course ... now I want to
change something that works by adding more flexibility to the form. That is
to say ... I want those default command buttons to be changeable as well. I
would like to do this by having the code take the default price from a
default table instead of being hard coded.

The only code I have currently for my click event is:

Me.PDM.Value = 252.36

I created TableDefault with a record key="M" that can give me DefDM that
contains 252.36. The same record will give me the default for other command
buttons as well.

The form's record source is unrelated to the default table. I know how to
update a table from a form but I don't know how to assign another table's
data to a variable to be used by the form.

I hope this is clearer than mud :-}

Please help!
 
Back
Top