Dear Alex or MVPS I need help...

W

wasim_sono

Dear Ale
I raised a query some days ago and u satisfied me. In continuation o
tha
Still a problem
Problem is that I'm getting the message or error " #Name" in th
textbo
field. any help please
I'm using the following code in these text boxes

Private Sub BatchNo_BeforeUpdate(Cancel As Integer
Me.BatchNo.DefaultValue = Me.BatchNo.Valu
DoCmd.Save acForm, Me.Nam
End Su

Private Sub KPOName_BeforeUpdate(Cancel As Integer
Me.KPOName.DefaultValue = Me.KPOName.Valu
DoCmd.Save acForm, Me.Nam
End Su
Field names in table are 'KPO' and 'Batch' and Textboxes names on for
ar
'KPOName' and 'BatchNo'
 
M

Marshall Barton

wasim_sono said:
Problem is that I'm getting the message or error " #Name" in the
textbox field. any help please.
I'm using the following code in these text boxes.

Private Sub BatchNo_BeforeUpdate(Cancel As Integer)
Me.BatchNo.DefaultValue = Me.BatchNo.Value
DoCmd.Save acForm, Me.Name
End Sub

Private Sub KPOName_BeforeUpdate(Cancel As Integer)
Me.KPOName.DefaultValue = Me.KPOName.Value
DoCmd.Save acForm, Me.Name
End Sub
Field names in table are 'KPO' and 'Batch' and Textboxes names on form
are
'KPOName' and 'BatchNo'.


A couple of issues here. Because the DefaultValue property
is string valued, if the thing you are setting it to is not
a number, then it must be enclosed in quotes:
Me.KPOName.DefaultValue = """" & Me.KPOName.Value & """"

Second, saving the entire form design just to remember the
new default values is a very risky thing to do. You should
save the values in a table and set the DefaultValues in the
forms Open event.
 
W

Wasim Yasin via AccessMonster.com

Dear Marshal
I'm really very sorry for the posting at some other groups. I appologize.

I tried as u explained:

Me.Batch_No.DefaultValue =""""&Me.Batch_No.Value&""""

But there is a
compile error:
Expected: end of statement

What do I now?

Thanx in advance.
 
W

Wasim Yasin via AccessMonster.com

When this code is run on multi user environment then an error occure on
'Do.Cmd....' Line.
What's ur idea about saving the values in table please tell me in detail.
and how can I resolve my problem.
thanx.
 
M

Marshall Barton

Wasim said:
I tried as u explained:

Me.Batch_No.DefaultValue =""""&Me.Batch_No.Value&""""

But there is a
compile error:
Expected: end of statement

My apologies, that should be 3 "s after the = sign
 
M

Marshall Barton

Wasim said:
When this code is run on multi user environment then an error occure on
'Do.Cmd....' Line.
What's ur idea about saving the values in table please tell me in detail.
and how can I resolve my problem.


Create a table, let's name it Defaults. Add two fields,
FieldName and FieldDefault, both Text fields. Set FieldName
as the Primary key. Populate the table with the names of
the fields that you want to save default values for.

Then, in your form's Unload event procedure, use some code
to save the values:

Dim db As DataBase
Set db = CurrentDb()
' repeat next line for each field
db.Execute "UPDATE Defaults " & _
"Set FieldDefault = """ & Me.<field> & """ " & _
"WHERE FieldName = ""<fieldname>""", _
dbFailOnError
. . .
Set db = Nothing

Note that I used <field> as a place marker that you need to
replace with the name of the text box that you want to save
its value. Also, <fieldname> is the marker for the name of
the field in the Defaults table. If you want, these two
name can be the same, but they do not have to be the same.

Use the form's Load event procedure to retrieve the saved
values and set the appropriate controls' DefaultValue:

Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Defaults")
'repeat next two statements for each field
rs.FindFirst "FieldName = ""<fieldname>"""
Me.<field>.DefaultValue = """ & rs!FieldDefault & """"
. . .
. . .
rs.Close: Set rs = Nothing
Set db = Nothing
 
D

Douglas J. Steele

Marshall Barton said:
My apologies, that should be 3 "s after the = sign

That's why I prefer

Me.Batch_No.DefaultValue = Chr$(34) & Me.Batch_No.Value & Chr$(34)

<g>
 
Top