There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard netgear network printer problem ram registry repair router slow software sound toshiba trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: Access 2003 form help

Reply  
Thread Tools
framarco's Avatar
Junior Member with 5 posts.
 
Join Date: Feb 2004
05-Oct-2009, 05:24 PM #1
Solved: Access 2003 form help
I am using Access 2003. I have a form, 'Protocollo', with a subform 'sfrm Prot' that is linked to the form on the field IDProt. The record source for the subform is a subset of the table [Prot_detail], and it contains only two records. The first record is displayed when btnIn on the subform is pushed and the second is displayed when btnOut is pushed. I want to change the font on the buttons to bold if the underlying record has any text in the 'Oggetto' field. I wrote a routine that is attached to the Current event of the subform, but it is not working. Here's what I wrote:

Dim rst As Recordset

set rst = Me.Recordsetclone

Me.btnIn.FontBold = IsNull(Me.Oggetto)
rst.MoveLast
Me.btnOut.FontBold = IsNull(Me.Oggetto)

rst.Close

Any ideas why this doesn't work? Can someone suggest something that would work, hopefully without using DLookup?
orangeCat1's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Dec 2008
Experience: Intermediate
05-Oct-2009, 11:29 PM #2
I think you need an IF statement along this line:::

If IsNull(Me.Oggetto) Then
Me.btnIn.FontBold = True
.....
framarco's Avatar
Junior Member with 5 posts.
 
Join Date: Feb 2004
06-Oct-2009, 03:51 AM #3
Actually, I originally wrote the routine using IF...THEN...ELSE statements. It still didn't work. Since IsNull() returns either True or False, the statements I have work. That is not where my problem is. The problem is that Me.Oggetto is only picking up the value from the record that is currently displayed. After the line rst.Movelast, I thought Me.Oggetto should get the value from the next record, but it is not doing that.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
06-Oct-2009, 06:15 AM #4
After the rst.Movelast add
msgbox rst.recordcount
which will tell you if the Subform has 1 or 2 more records.
You could also use
rst.movenext
to move to the second record.
framarco's Avatar
Junior Member with 5 posts.
 
Join Date: Feb 2004
06-Oct-2009, 11:57 AM #5
Quote:
Originally Posted by OBP View Post
After the rst.Movelast add
msgbox rst.recordcount
which will tell you if the Subform has 1 or 2 more records.
You could also use
rst.movenext
to move to the second record.
rst.recordcount shows 2.

I have made some progress on this, but it is still not working as I want. I now have:

Set rst = Me.RecordsetClone

rst.MoveFirst
Me.btnEntrata.FontBold = Not IsNull(Oggetto)
rst.MoveLast
Me.btnUscita.FontBold = Not IsNull(Oggetto)
Me.Refresh

rst.Close

What happens is that if the 'Oggetto' field in the currently displayed record is blank, both btnIn and btnOut will display normal text. If, on the other hand, the 'Oggetto' field has something in it, both buttons will display bold text. I want to be able to display one button with bold text and one with normal text, based on whether the Oggetto field (not the form control) has text in it or not.

My gut tells me that the problem lies with the 'IsNull(Oggetto)' statement. If I set a breakpoint at the beginning of the routine and check the value of Oggetto while the routine runs, the value does not change after the rst.MoveLast statement runs.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
06-Oct-2009, 01:33 PM #6
Try
Set rst = Me.RecordsetClone

rst.MoveFirst
Me.btnEntrata.FontBold = Not IsNull(rst.Oggetto)
rst.MoveLast
Me.btnUscita.FontBold = Not IsNull(rst.Oggetto)
Me.Refresh

rst.Close
framarco's Avatar
Junior Member with 5 posts.
 
Join Date: Feb 2004
06-Oct-2009, 05:01 PM #7
Thumbs up Success
OBP: That caused a "Compilation error. Method or data member not found."

But it gave me the thought that solved the problem. Here is the winning code:

Set rst = Me.RecordsetClone
rst.MoveFirst
Me.btnEntrata.FontBold = Not IsNull(rst.Fields("Oggetto"))
rst.MoveLast
Me.btnUscita.FontBold = Not IsNull(rst.Fields("Oggetto"))
Me.Refresh
rst.Close


Why this works and your solution did not is beyond me.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
09-Oct-2009, 07:04 AM #8
Access VBA is full of idiosyncrasies like that.
Reply

Tags
access, form, recordset

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:19 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.