Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Label Caption doesn't work as expected

Status
Not open for further replies.

dr00bie

Programmer
Feb 19, 2004
108
US
I have a report that when opened, it opens a form named Months that has a dropdown of all of the months of the year, when the user selects a month and clicks Get Report, the report is loaded and the record source is set to a stored procedure (yes, it is an ADP) with the month as a parameter.

Here is my code,

Code:
DoCmd.Maximize
    
Dim varMonth As String
Dim varMonthInt As Integer
        
DoCmd.OpenForm "Month", acNormal, , , , acDialog
    
varMonth = Forms!Month.Month
    
Select Case varMonth
  Case "January"
    varMonthInt = 1
  Case "February"
    varMonthInt = 2
  Case "March"
    varMonthInt = 3
  Case "April"
    varMonthInt = 4
  Case "May"
    varMonthInt = 5
  Case "June"
    varMonthInt = 6
  Case "July"
    varMonthInt = 7
  Case "August"
    varMonthInt = 8
  Case "September"
    varMonthInt = 9
  Case "October"
    varMonthInt = 10
  Case "November"
    varMonthInt = 11
  Case "December"
    varMonthInt = 12
  Case Else
    varMonthInt = "ERROR!"
End Select
    
Dim strRecordSource As String
strRecordSource = "Exec [spPhysicalsByMonth] " & varMonthInt
Me.RecordSource = strRecordSource
    
Me.lblTitle.Caption = "Physicals Due - " & varMonth
'Me.lblTitle.Caption = varMonth
    
Forms!Month.Visible = False

When I try to label the report as "Physicals Due - [MonthSelected]", it doesn't work, but if I try to label the report with the month only, it works.

What can I do to fix this?

Thanks,
Drew
 
Try replacing the dash character with something else - MAYBE Access is trying to evaluate it as an expression since there is an integer; or try using CStr(varMonth)
instead of varMonth....

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
Ok... I am a dummy! Sorry for wasting your time genomon... My problem was that my label was not long enough to show the month, but it was throwing me off because it would show "Physicals Due - " and then stop. When I removed the dash, it showed up like "Physicals Due J".

Thanks for spurring my brain to figure my stupidity out.

Thanks,
Drew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top