Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7

    how to create a text sequence generator in ms access

    how to create a text sequence generator in ms access??
    I have a number sequence generator but I would like to create a generator that repeats a given name to a given sequence of number.
    this is the number sequence:
    Private Sub cmdgen_Click()
    Dim sealnum As Integer


    For sealnum = box1.Value To box2.Value

    CurrentDb.Execute "INSERT INTO sealinventorytbl ([sealnum]) " _
    & "VALUES (" & sealnum & ")"



    Next sealnum


    End Sub

    any advice out there? thanks in advance

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    dim db as database
    dim sSQL as string
    dim StartValue
    
    set db = current db
    StartValue = box1
    
    do while StartValue <= Box2
        sSQL = "INSERT INTO sealinventorytbl ([SealNum]) VALUES (" & StartValue & ")"
        db.execute ssql
        StartValue = StartValue + 1 'or whatever your increment is
    loop
    
    
    set db = nothing

  4. #4
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by rpeare View Post
    Code:
    dim db as database
    dim sSQL as string
    dim StartValue
    
    set db = current db
    StartValue = box1
    
    do while StartValue <= Box2
        sSQL = "INSERT INTO sealinventorytbl ([SealNum]) VALUES (" & StartValue & ")"
        db.execute ssql
        StartValue = StartValue + 1 'or whatever your increment is
    loop
    
    
    set db = nothing
    i'll be taking the name from an input 'techname' also box1 and box2 will have the lower and upper limit respectively of the sequence of numbers.

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If there is a question there I don't see it

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I don't see a question either.
    Perhaps the OP has a solution. If not perhaps he/she would show us a sample of the expected output.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    how to create a text sequence generator in ms access??
    Maybe
    Code:
    Private Sub cmdgen_Click()
        Dim sealnum As Integer
        Dim strText As String
        Dim techname As String
        Dim TextSequence As String
    
        techname = "WaterPump"   '<<= this could be a reference to a control on the form
    
        For sealnum = Me.box1 To Me.box2  '<-references to controls on the form
            TextSequence = techname & sealnum
    
            strText = "INSERT INTO sealinventorytbl (sealnum)  VALUES ('" & TextSequence & "')"
            '        Debug.Print strText   'for debugging
            CurrentDb.Execute strText.dbFailOnError
    
        Next sealnum
    
    End Sub
    (Code based on rpeare's code from Post#3)

    Note the text delimiters in the VALUES clause
    Last edited by ssanfu; 02-10-2015 at 01:28 PM.

  8. #8
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7
    Click image for larger version. 

Name:	sequence generator.PNG 
Views:	11 
Size:	9.3 KB 
ID:	19633
    here is a better look at what i'm saying, the numbers are generating but not the text

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What is the format of your sequence?

    Is it 'Ashuton-001' or is it 1-001 (ashutons's ID from the combo box) or is it 001-Ashuton

    the code ssnafu modified from my original post would work just fine. The only thing you'd need to change is the statement:

    techname = comboboxname.column(1)

    if you want the text to be part of the sequence

    techname = comboboxname

    if you want the bound column (assuming it's the first column, combo boxes and list boxes are 0 indexed) to be part of the text sequence

  10. #10
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by rpeare View Post
    What is the format of your sequence?

    Is it 'Ashuton-001' or is it 1-001 (ashutons's ID from the combo box) or is it 001-Ashuton

    the code ssnafu modified from my original post would work just fine. The only thing you'd need to change is the statement:

    techname = comboboxname.column(1)

    if you want the text to be part of the sequence

    techname = comboboxname

    if you want the bound column (assuming it's the first column, combo boxes and list boxes are 0 indexed) to be part of the text sequence
    The format of the sequence is as follows:
    1 Ashuton
    2 Ashuton
    3 Ashuton
    .
    .
    .
    20 Ashuton

    how can your original program be modify to capture that idea?

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Alexander,

    Based on the comments and suggestions by others, it isn't clear to me that a "text sequence generator" means the same thing to you and readers. When I see a generator, I'm thinking "test data generator" or "random number generator". I think your definition is more like "How to create a custom code/identifier for products/items/things".

    Perhaps you could clarify by means of an example or two.

    UPDATE: seems are posts were made at the same time

    Code:
    ....
    MyText = "Ashuton"
    For i = 1 to  20
      debug.print i & "-" & Mytext
    Next i
    .............
    Last edited by orange; 02-10-2015 at 08:31 AM. Reason: added logic to show generation of number and text.

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    ssnafu's modified code will work just fine with the change in the

    techname = combobox.column(x)

    addition, where combobox is the name of your technician combobox and x is the column where the technician name appears (remember combo boxes and list boxes are 0 indexed so the second column is .column(1)) and alter the order of his textsequence variable and you should be fine.

  13. #13
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by rpeare View Post
    ssnafu's modified code will work just fine with the change in the

    techname = combobox.column(x)

    addition, where combobox is the name of your technician combobox and x is the column where the technician name appears (remember combo boxes and list boxes are 0 indexed so the second column is .column(1)) and alter the order of his textsequence variable and you should be fine.
    ok thanks a million to all of you guys that contributed.

    hi, when I executed the code it gave Compile error: Invalid qualifier, and it highlights strText in the line 'CurrentDb.Execute strText.dbFailOnError'
    what does that mean? any advise on how to deal with that error?

  14. #14
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what is your code and what is your table design?

    you have to modify the code to be in line with your actual form/field/table names

  15. #15
    Alexander is offline Novice
    Windows 8 Access 2007
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by rpeare View Post
    what is your code and what is your table design?

    you have to modify the code to be in line with your actual form/field/table names

    the table and the form
    Click image for larger version. 

Name:	generator.png 
Views:	8 
Size:	20.3 KB 
ID:	19635

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-21-2014, 02:28 PM
  2. Appointment Generator
    By cheechootrain in forum Access
    Replies: 15
    Last Post: 04-23-2013, 12:37 PM
  3. Replies: 4
    Last Post: 04-09-2013, 03:54 PM
  4. Replies: 2
    Last Post: 06-06-2012, 09:35 AM
  5. Account ID - Generator
    By sschrader1 in forum Queries
    Replies: 4
    Last Post: 04-09-2012, 08:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums