A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Assign a value to a field from the Format event



 
 
Thread Tools Display Modes
  #1  
Old July 8th, 2009, 11:38 PM posted to microsoft.public.access.reports
Goldar
external usenet poster
 
Posts: 29
Default Assign a value to a field from the Format event

I am listing a file whose records contain the fields "Item Number" and
"Description". When the program encounters a record that has a blank Item
Number or a blank Description, I want to replace the offending field with the
work "Blank". Here is the code that I have in my Detail section Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Item Number], "") = "" Or isBlank(Me![Item Number]) Then
Me![Item Number] = "Blank"
End If
If Nz(Me![Description], "") = "" Or isBlank(Me![Description]) Then
Me![Description] = "Blank"
End If
Cancel = False
End Sub

When I encounter a blank field, I get an error on the assignment of the
contstant to the offending field ([Item Number] or [Description]. I also get
the message "You can't assign a value to this object". What am I doing wrong?

Thanks
  #2  
Old July 9th, 2009, 12:07 AM posted to microsoft.public.access.reports
Klatuu
external usenet poster
 
Posts: 7,074
Default Assign a value to a field from the Format event

Rather than assign the field as the control source for the control, use an
expression like this:

=IIf(Len(Nz([Item Number],"")) = 0, "Blank", [Item Number])
--
Dave Hargis, Microsoft Access MVP


"Goldar" wrote:

I am listing a file whose records contain the fields "Item Number" and
"Description". When the program encounters a record that has a blank Item
Number or a blank Description, I want to replace the offending field with the
work "Blank". Here is the code that I have in my Detail section Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Item Number], "") = "" Or isBlank(Me![Item Number]) Then
Me![Item Number] = "Blank"
End If
If Nz(Me![Description], "") = "" Or isBlank(Me![Description]) Then
Me![Description] = "Blank"
End If
Cancel = False
End Sub

When I encounter a blank field, I get an error on the assignment of the
contstant to the offending field ([Item Number] or [Description]. I also get
the message "You can't assign a value to this object". What am I doing wrong?

Thanks

  #3  
Old July 9th, 2009, 12:46 AM posted to microsoft.public.access.reports
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Assign a value to a field from the Format event

Goldar wrote:


I am listing a file whose records contain the fields "Item Number" and
"Description". When the program encounters a record that has a blank Item
Number or a blank Description, I want to replace the offending field with the
work "Blank". Here is the code that I have in my Detail section Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Item Number], "") = "" Or isBlank(Me![Item Number]) Then
Me![Item Number] = "Blank"
End If
If Nz(Me![Description], "") = "" Or isBlank(Me![Description]) Then
Me![Description] = "Blank"
End If
Cancel = False
End Sub

When I encounter a blank field, I get an error on the assignment of the
contstant to the offending field ([Item Number] or [Description]. I also get
the message "You can't assign a value to this object". What am I doing wrong?



You can not assign a value to a bound text box.

Instead of using code, you can use an expression in the text
box:
=IIf(Nz(Trim([Item Number]), "") = "", "Blank", [Item
Number])

--
Marsh
MVP [MS Access]
  #4  
Old July 9th, 2009, 01:09 AM posted to microsoft.public.access.reports
Goldar
external usenet poster
 
Posts: 29
Default Assign a value to a field from the Format event

Thanks to you both for the suggestion. I didn't know that you can't assign a
value to
a bound text box. Both your suggestions worked fine.
"Marshall Barton" wrote:

Goldar wrote:


I am listing a file whose records contain the fields "Item Number" and
"Description". When the program encounters a record that has a blank Item
Number or a blank Description, I want to replace the offending field with the
work "Blank". Here is the code that I have in my Detail section Format event:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Item Number], "") = "" Or isBlank(Me![Item Number]) Then
Me![Item Number] = "Blank"
End If
If Nz(Me![Description], "") = "" Or isBlank(Me![Description]) Then
Me![Description] = "Blank"
End If
Cancel = False
End Sub

When I encounter a blank field, I get an error on the assignment of the
contstant to the offending field ([Item Number] or [Description]. I also get
the message "You can't assign a value to this object". What am I doing wrong?



You can not assign a value to a bound text box.

Instead of using code, you can use an expression in the text
box:
=IIf(Nz(Trim([Item Number]), "") = "", "Blank", [Item
Number])

--
Marsh
MVP [MS Access]

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:23 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.