Retrieving value from a table

  • Thread starter Thread starter Ran BD
  • Start date Start date
R

Ran BD

guys,
is the correct way to retrieve a value from within a table is as follows:
Me.Mis_Han.DefaultValue = """ & DMax(([Sapak_Tbl]![Mis_han])+1) & """

while [Sapak_tbl] is the Table anf [Mis_Han] is the field stored in the
table.

thanks.
 
Ran BD said:
guys,
is the correct way to retrieve a value from within a table is as follows:
Me.Mis_Han.DefaultValue = """ & DMax(([Sapak_Tbl]![Mis_han])+1) & """

while [Sapak_tbl] is the Table anf [Mis_Han] is the field stored in the
table.

Ran,

if you set the cursor in the code editor on DMax and press F1, you'll
get the Help item on DMax. Take a look to the syntax, there are 2
mandatory parameters, not one (there are also examples). So your
expression for DMax would be:

DMax("[Mis_Han]", "[Sapak_tbl]")

and the default value:
Me!Mis_Han.DefaultValue = DMax("[Mis_Han]", "[Sapak_tbl]") + 1

I'd suppose, Mis_Han is numeric, therefore no quotes.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
guys,
is the correct way to retrieve a value from within a table is as follows:
Me.Mis_Han.DefaultValue = """ & DMax(([Sapak_Tbl]![Mis_han])+1) & """

while [Sapak_tbl] is the Table anf [Mis_Han] is the field stored in the
table.

thanks.

Not particularly. You have a couple of errors.

This is a way to set the Default property of a textbox named Mis_Han
on a Form, not to "retrieve a value".

The errors:

The DMax() function takes three string arguments, of which the third
is optional; you've only given it one. If you want DMax() to return
the largest value of the field Mis_Han from Sapak_Tbl, the correct
syntax would be

DMax("[Mis_Han]", "[Sapak_Tbl]")

The third argument is not needed unless you want to apply criteria to
filter the records over which the maximum will be calculated.

Also, you have the quotemarks wrong; you should have """" (four
quotes) instead of three. Two consecutive " characters inside a "
delimited string translate to a single quotemark; if the largest value
of Mis_Han is 333, using four quotes will give you

Me.Mis_Han.DefaultValue = "334"
 
John, it helped and I am getting the correct value while putting it in the
default value property.
now assuming I want to put it in the on get focus property what would be the
syntax then ?
I was using - me.mis_han.defaultvalue =DMax("[Mis_Han]","[Sapak_Tbl]")+1 -
and was getting no value at all

thanks for the help.

Ran


John Vinson said:
guys,
is the correct way to retrieve a value from within a table is as follows:
Me.Mis_Han.DefaultValue = """ & DMax(([Sapak_Tbl]![Mis_han])+1) & """

while [Sapak_tbl] is the Table anf [Mis_Han] is the field stored in the
table.

thanks.

Not particularly. You have a couple of errors.

This is a way to set the Default property of a textbox named Mis_Han
on a Form, not to "retrieve a value".

The errors:

The DMax() function takes three string arguments, of which the third
is optional; you've only given it one. If you want DMax() to return
the largest value of the field Mis_Han from Sapak_Tbl, the correct
syntax would be

DMax("[Mis_Han]", "[Sapak_Tbl]")

The third argument is not needed unless you want to apply criteria to
filter the records over which the maximum will be calculated.

Also, you have the quotemarks wrong; you should have """" (four
quotes) instead of three. Two consecutive " characters inside a "
delimited string translate to a single quotemark; if the largest value
of Mis_Han is 333, using four quotes will give you

Me.Mis_Han.DefaultValue = "334"
 
John, it helped and I am getting the correct value while putting it in the
default value property.
now assuming I want to put it in the on get focus property what would be the
syntax then ?
I was using - me.mis_han.defaultvalue =DMax("[Mis_Han]","[Sapak_Tbl]")+1 -
and was getting no value at all

The Default value is applied at the time a new record is initially
created - BEFORE you setfocus to the textbox.

I guess the question is: what are you trying to accomplish? I'm
*guessing* that you're implementing a Custom Counter; if so, the
Form's BeforeInsert event would be the appropriate event, and rather
than setting the Default property you'ld just set the control itself
to the DMax:

Private Sub Form_BeforeInsert(Cancel as Integer)
Me!txtMis_Han = DMax("[Mis_Han]", "[Sapak_Tbl]") + 1
End Sub
 
Back
Top