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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Defaults in Cascaded Combo Boxes



 
 
Thread Tools Display Modes
  #1  
Old October 26th, 2009, 01:07 PM posted to microsoft.public.access.forms
merry_fay
external usenet poster
 
Posts: 49
Default Defaults in Cascaded Combo Boxes

Hi, I have a form with 2 combo boxes.

In the first (UCTableYear), I select the Year & in the 2nd (UCTableVersion),
I select the version I want to use from that year from the table Unit Cost
I've managed to set the default for the year to the maximum year in the
table, but I then want the default for the Version to be the maximum version
corresponding to the same year.
This is the code I have:
Private Sub Form_Load()
Me!UCTableYear.Value = Nz(DMax("[Year]", "[unit cost]", ""), 0)
End Sub

Private Sub UCTableYear_AfterUpdate()
Form.UCTableVersion.Requery
Me!UCTableVersion.Value = Nz(DMax("[Version]", "[unit cost]", ""), 0)
End Sub

It's the bit 'Me!UCTableVersion.Value = Nz(DMax("[Version]", "[unit cost]",
""), 0)' which isn't working. What do I need to do to make it set itself to
the maximum available for the year appearing in the 1st combo box?

Thanks



  #2  
Old October 26th, 2009, 01:50 PM posted to microsoft.public.access.forms
Tom van Stiphout[_2_]
external usenet poster
 
Posts: 1,653
Default Defaults in Cascaded Combo Boxes

On Mon, 26 Oct 2009 06:07:01 -0700, merry_fay
wrote:

Don't leave the third argument of DMax() empty, but set it to:
"[Year]=#" & Me!UCTableYear.Value & "#"
I am assuming Year is your field name. Not a good choice because it is
a reserved word. Date values need to be wrapped in #-signs.

-Tom.
Microsoft Access MVP


Hi, I have a form with 2 combo boxes.

In the first (UCTableYear), I select the Year & in the 2nd (UCTableVersion),
I select the version I want to use from that year from the table Unit Cost
I've managed to set the default for the year to the maximum year in the
table, but I then want the default for the Version to be the maximum version
corresponding to the same year.
This is the code I have:
Private Sub Form_Load()
Me!UCTableYear.Value = Nz(DMax("[Year]", "[unit cost]", ""), 0)
End Sub

Private Sub UCTableYear_AfterUpdate()
Form.UCTableVersion.Requery
Me!UCTableVersion.Value = Nz(DMax("[Version]", "[unit cost]", ""), 0)
End Sub

It's the bit 'Me!UCTableVersion.Value = Nz(DMax("[Version]", "[unit cost]",
""), 0)' which isn't working. What do I need to do to make it set itself to
the maximum available for the year appearing in the 1st combo box?

Thanks


 




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 12:19 PM.


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