Combo Box Defaults to blank (1 Viewer)

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
I am a total novice here. I have a combo box which lists two columns, a Date and a Code, from a related table. The box initially displays as blank. I want it to initially display the most recent date and code in the table, then the rest upon a click, as a drop-down. That part is already working. My trouble is just in making it initially show tha lastest record rather than a blank. Can you help me?
 

boblarson

Smeghead
Local time
Today, 16:10
Joined
Jan 12, 2001
Messages
32,059
in the form's On Load event you could use

Me.ComboNameHere = DMax("[DateFieldHere]", "TableNameHere")

Are there more than one of the max dates that match up with a different code? If so how do you determine which code to use?
 

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
I never heard of an On Load event. I am trying to use the Default Value property. I did not know there were form events. I was looking at the box itself and its definition. I will have to investigate this thing with "Load Events." By the way, when you say "Me.ComboNameHere, what does the "Me" represent?
 

boblarson

Smeghead
Local time
Today, 16:10
Joined
Jan 12, 2001
Messages
32,059
I never heard of an On Load event. I am trying to use the Default Value property.
Default values are limited in what you can put there.
By the way, when you say "Me.ComboNameHere, what does the "Me" represent?

From the Glossary on my webpage:
boblarson said:
This is a programming shortcut which lets the programmer refer to the current CLASS object. Most of the time, in Access, you would be referring to a form or report using this. It can also apply to custom classes as well, but is less prevalent unless custom classes are being used.
Let's say you have a form named "frmMain" and you have a text box there called "txtEntry" and you wanted to refer to that text box in code. A fully-qualified reference would be Forms!frmMain.txtEntry but you could also refer to it using the shortcut (as long as the code is ON frmMain): Me.txtEntry
 

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
Bob:


Me.ComboNameHere = DMax("[DateFieldHere]", "TableNameHere")

Are there more than one of the max dates that match up with a different code? If so how do you determine which code to use? __________________

Combo46 is a displays the dates of various correspondences, the Code (Let_Type describes the correspondence mailed. I could have several identical dates with different codes, signifying different letters sent on that date. I would like to always display as the default the most recent one. Your code above would come out as:

Me.Combo46 = Dmax("[Let_Date", "Donor_Letters")

When I enter this into the On Load Expression builder, it re-punctuates it to:
=[Me].[Combo46]=DMax("[Let_Date","Donor_Letters")

when I go to layout mode delivers the following error message:

The object doesn't contain the Automation Object "Me."
 

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
I tried this, to no effect. See attachment
 

Attachments

  • NewPicture007.jpg
    NewPicture007.jpg
    96.2 KB · Views: 89

boblarson

Smeghead
Local time
Today, 16:10
Joined
Jan 12, 2001
Messages
32,059



Oh, and you would want to change the code to this (so as to not overwrite existing data):

Code:
Private Sub Form_Load()
[B][COLOR=red]If Me.NewRecord Then[/COLOR][/B]
   Me.Combo46 = DMax("[Let_Date]", "Donor_Letters")
[B][COLOR=red]End If[/COLOR][/B]
End Sub
 

Attachments

  • jimmonator.jpg
    jimmonator.jpg
    93.3 KB · Views: 245

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
Hey, Bob, Thanks for all your help! Still not working though. Please see attachment.

By the way, I see you're in Portland. Me too, I'm up at OHSU.
 

Attachments

  • NewPicture012.jpg
    NewPicture012.jpg
    82.1 KB · Views: 87

jimmonator

New member
Local time
Today, 16:10
Joined
Apr 12, 2011
Messages
8
This problem I still have not solved. Can you offer any further ideas?
 

Users who are viewing this thread

Top Bottom