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  

User-defined function in combo box



 
 
Thread Tools Display Modes
  #1  
Old January 17th, 2008, 07:13 PM posted to microsoft.public.access.forms
Tangz
external usenet poster
 
Posts: 6
Default User-defined function in combo box

I am trying to the list years in a combo box based on current year:

e.g: current year -2008
combo box values : 2007,2008,2009,2010,2011,2012

I found a function that calculates this value:

Function YearLoop() As String

Dim YearHold As Date
Dim strSQL As String
Dim i As Integer
Dim n As Integer
strSQL = ""

For i = -1 To 5
YearHold = DateSerial(Year(Date) + i, 1, 1)
strSQL = strSQL & Format(YearHold, "yyyy") & "; "
Next i

YearLoop = strSQL
End Function

I tried to call this function from the combo box by setting
RowSourceType to be YearLoop (I also tried =YearLoop) but the combo
box doesn't seem to be calling that function.

Can anyone suggest how to use the function YearLoop() to populate the
combo box.

Thanks
Thangam
  #2  
Old January 17th, 2008, 07:51 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default User-defined function in combo box

You could do it in the form Load event.
Make sure the row source type of the combo box is Value List.

Then to call the loop function:
strList = YearLoop
strList = Left(strList, Len(strList) -1) 'Takes off the last semicolon
Me.MyCombo.RowSource = strList
--
Dave Hargis, Microsoft Access MVP


"Tangz" wrote:

I am trying to the list years in a combo box based on current year:

e.g: current year -2008
combo box values : 2007,2008,2009,2010,2011,2012

I found a function that calculates this value:

Function YearLoop() As String

Dim YearHold As Date
Dim strSQL As String
Dim i As Integer
Dim n As Integer
strSQL = ""

For i = -1 To 5
YearHold = DateSerial(Year(Date) + i, 1, 1)
strSQL = strSQL & Format(YearHold, "yyyy") & "; "
Next i

YearLoop = strSQL
End Function

I tried to call this function from the combo box by setting
RowSourceType to be YearLoop (I also tried =YearLoop) but the combo
box doesn't seem to be calling that function.

Can anyone suggest how to use the function YearLoop() to populate the
combo box.

Thanks
Thangam

  #3  
Old January 17th, 2008, 08:01 PM posted to microsoft.public.access.forms
Tangz
external usenet poster
 
Posts: 6
Default User-defined function in combo box

It works !! Thank you Dave ! I really appreciate your help.

Thangam

 




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 11:41 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.