Results 1 to 11 of 11

Thread: combo box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    combo box

    how can i automatically add a new number when i click the combo box.

    example my inside my combo box i have a course of NURSING, IT, Engineering
    then i choose Nursing the txtBatchNUm will automatically generate NUR-0002.
    hope anyone can help....

    VB Code:
    1. Private Sub cmdSave_Click()
    2.    With tbCourse
    3.            .MoveFirst
    4.             .Find "BatchNumber = '" & txtBatchNum & "'"
    5.             If .Fields(2) = txtBatchNum Then
    6.                 MsgBox "Batch Number Already Exist.", vbInformation, "Titus School of Multimedia"
    7.                 txtBatchNum = ""
    8.                 txtBatchNum.SetFocus
    9.             ElseIf .EOF = True Then
    10.                 .AddNew
    11.                 AddFields
    12.                 MsgBox "Batch Number successfully saved to the record.", vbInformation, "Titus School of Multimedia"
    13.                 .Update
    14.                 .Requery
    15.                 txtBatchNum = ""
    16.                 cmbCourse.Clear
    17.                 cmbDepartment.Clear
    18.                 txtNoSeat = ""
    19.              End If
    20.         End With
    21. End Sub
    22.  
    23. Private Sub Form_Load()
    24. With tbCourse
    25.  If .BOF = True And .EOF = True Then
    26.         Refresh
    27.     Else
    28.         Do Until .EOF
    29.             cmbCourse.AddItem (.Fields(0))
    30.             .MoveNext
    31.         Loop
    32.     End If
    33. End With
    34.  
    35. With tbDepartment
    36.  If .BOF = True And .EOF = True Then
    37.         Refresh
    38.     Else
    39.         Do Until .EOF
    40.             cmbDepartment.AddItem (.Fields(0))
    41.            .MoveNext
    42.         Loop
    43.     End If
    44. End With
    45.  
    46. End Sub
    47.  
    48. Private Sub AddFields()
    49.  
    50. With tbBatch
    51.     .Fields(0) = cmbCourse
    52.     .Fields(1) = txtNoSeat
    53.     .Fields(2) = txtBatchNum
    54.     .Fields(3) = cmbDepartment
    55. End With
    56.  
    57. End Sub

  2. #2
    Junior Member
    Join Date
    Jan 2007
    Posts
    26

    Re: combo box

    You can do this...example:-
    Private Sub Combo1_Change()
    if combo1.text = "NURSING" Then
    txtBatchNUm.text = XXXXXX
    end If
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: combo box

    theres a database for the course example
    CourseName BatchNumber
    Nursing Nur-0001
    Engineering Eng-0001
    IT IT-0001

    the the combo box will be filled up by the Fields of the CourseName
    example i choose Nursing the it will automatically add Nur-0002

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Question combo box

    can anynone help me about combo box if i choose one in combo box the text box will automatically add a new number like this NUR-00001

    VB Code:
    1. Private Sub cmbCourse_Click()
    2. a = cmbCourse.Text
    3. 'tmp = tbCourse.Fields(2)
    4.  
    5. Call rload
    6.  Do While tbCourse!CourseName <> a
    7.  tbCourse.MoveNext
    8.  If tbCourse!CourseName = a Then
    9.  txtBatchNum.Text = tbCourse!BatchNumber + temp
    10.  tmp = Left(tmp, 3) & (Format(CInt(Right(tmp, 4)) + 1, "00#"))
    11.     End If
    12. Loop
    13.  
    14. End Sub
    it have an error on
    VB Code:
    1. tmp = Left(tmp, 3) & (Format(CInt(Right(tmp, 4)) + 1, "00#"))

  5. #5
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: combo box

    You already asked this question.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: combo box

    yes can anyone help me with this

  7. #7
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Smile Re: combo box

    Quote Originally Posted by mheiy
    yes can anyone help me with this
    I didn't get ..what is the value of temp???

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: combo box

    the Batch Number have a format of this NUR-0001 how can i add another batch number with the same format

  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: combo box

    you mean to say that you want to make the same format of a field to another field...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  10. #10
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: combo box

    Hi

    Does this help?


    VB Code:
    1. 'If you want in this format NUR-0001
    2. tmp = Left(tmp, 4) & Format(Right(tmp, 4)+1, "0000")
    3.  
    4. 'If you want in this format NUR-00001
    5. tmp = Left(tmp, 4) & Format(Right(tmp, 5)+1, "00000")
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: combo box

    Duplicate threads merged.

    Please do not create more than one thread for the same question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width