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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label paragraphs (a, b,c, d) 1

Status
Not open for further replies.

kporters

Programmer
Jan 11, 2002
21
US
I've created a report to have group headers based on product id. I want to give the first product id an "A" in the header, the next a "B" in the header, and so on and if the product id's are over 26, to start the 27th product id w/"AA", then "AB". Is there a way of doing this w/code and not having to create a table?
 
Function getNextPara(psCurrPara As String)
' examples
' ?getNextPara("") ' returns "A"
' ?getNextPara("A") ' returns "B"
' ?getNextPara("Z") ' returns "AA"
' ?getNextPara("AA") ' returns "AB"
' ?getNextPara("AZ") ' returns "AAA"

Dim sCurrPara As String
sCurrPara = UCase(Trim(psCurrPara))

If sCurrPara = "" Then
getNextPara = "A"
Exit Function
End If

Dim sRightChar As String
Dim iCharLen As Integer

Dim sRet As String
Dim sCharStr As String
sCharStr = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

sRightChar = Right(sCurrPara, 1)
iCharLen = Len(sCurrPara)

Select Case sRightChar
Case "Z"
sRet = Left(sCharStr, iCharLen) & "A"
Case Else
sRet = Left(sCurrPara, iCharLen - 1) & Chr(Asc(sRightChar) + 1)
End Select

getNextPara = sRet


End Function
 
thanks,
i tested your code, it stays in a loop on the first if all para's are A's
 
in my report, getnextpara remains an "A" for all product id's, any suggestions where i might have gone wrong?
thanks
 
Ok, I understand. What you want to do is create a variable in your form that is global to the whole form.
Go into the VBA module of your report and put this there:

Option Compare Database
Dim msPara As String

Now on your header print event you will put this. This code assumes that your text box on the report is named txtPara:

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
msPara = getNextPara(msPara)
Me.txtPara = msPara
End Sub

The var msPara will get incremented each time to A, B ... AA, AB ... etc

 
Another question...are you emulating the Excel column format? In other words, after AZ would you want BA or AAA?
 
yes, I'm attempting to emulate the Excel column format, I did try to change the code to go to BA after AZ but have been unsuccessful.
 
Use this function istead:

Function getNextPara(piColIndex As Integer) As String

'* returns the alpha representation of an Excel column from a numeric
'* sample calls:
' ?getNextPara(1) ' A
' ?getNextPara(256) ' IV
' ?getNextPara(53) ' BA

Dim sRightPart As String
Dim sLeftPart As String

' base 26, sort of
sRightPart = Chr(64 + IIf(piColIndex Mod 26 = 0, 26, piColIndex Mod 26))
sLeftPart = ""
If piColIndex > 26 Then
sLeftPart = Chr(64 + IIf(piColIndex Mod 26 = 0, (piColIndex / 26 - 1), Int(piColIndex / 26)))
End If
getNextPara = sLeftPart & sRightPart

End Function
----------------------------------

Now you need to make some slight modifications to the VBA code in your report:

Option Compare Database
Dim miPara As Integer

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
miPara = miPara + 1
Me.txtPara = getNextPara(miPara)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top