?
Solved

Creating Sequential Letter Generator in vba. AA AB Revisted

Posted on 2012-08-24
5
Medium Priority
?
1,169 Views
Last Modified: 2012-08-27
On my previous request on this subject I was provided a code solution that produced a string in the form of:

[Function ColXL(ByVal abc As String) As Long
' ** Covert Number to Letter Seq**
 ' * 108 to DD
 '?ColXL("--AA")
 '?ColXL("ZZZZZ")

abc = Trim(Replace(UCase(abc), "-", ""))
    Do While Len(abc)
        ColXL = ColXL * 26 + (Asc(abc) - vbKeyA + 1)
        abc = Mid(abc, 2)
    Loop
End Function]

- - - - A thru ZZZZZ.   It  works great.   Now I need to popluate a listbox or combobox with values the user can select from.

For Example:
User need 3 Seqs ID's generated.  And the last Seq ID was "C"
User inputs "3" in a textbox and the list box would be populated with "D" ,  "E" , " F" to select from.

User inputs "4" and the Last Seq ID was  "AB"
the list box would be populated with "AC", "AD", "AE", "AF"

User inputs "2" and the Last Seq ID was  "AAAA"
the list box would be populated with "AAAB", "AAAC" etc.

This would occur all the way up to "ZZZZZ"

What's the best way to do this?  
Array?
Table were I update the recordset (rowsource)?

Arrrgh.

Thanks
0
Comment
Question by:darkdell
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:als315
ID: 38330980
Test sample (with harfang's functions)
DBlistseq.accdb
0
 

Author Comment

by:darkdell
ID: 38337037
als315

Thank you
That is very very close! But the listbox is including the orginal letter as well.

Like I stated, I need the "next" values indicated by the Q-ty values, excluding the current letter value.  That's why I'm having trouble (the loops).

So "A" with Q-ty 2 would give me "B","C"  not  "A" & "B"
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38337552
Can you take a step back and explain the ultimate use for this system.

It seems like it is being used for interaction with Excel.
So perhaps an Excel based solution might be more fitting...?
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 38337907
No problems. Change function to:
Sub fill_list(ByVal Str As String, N As Integer)
Dim i As Integer
i = 0
With Me.MyListBox
  For i = .ListCount - 1 To 0 Step -1
        .RemoveItem i
  Next i
  For i = 0 To N - 1
        Str = XLcL(ColXL(Str) + 1)
        .AddItem Str
  Next i
End With
End Sub

Open in new window

String  .AddItem Str should be moved down
0
 

Author Comment

by:darkdell
ID: 38338456
I was going to

Me.MyListBox.RemoveItem 0

at the end of the Sub fill_list code but your solution is much better thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question