Results 1 to 2 of 2
  1. #1
    christing is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    10

    Fail auto generate ID on textbox

    I fail auto generate id on my textbox can someone pls help me take a look. i have tried many method to auto generate id on my textbox but when user success key in data to the database but my textbox id still fail auto generate. if i stop and stop and play the program again the id will continue.

    Private Sub getNextNumber()
    If Not app.State = ConnectionState.Open Then
    'open connection
    app.Open()
    End If


    Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app)
    Dim dt As New DataTable
    'fill data to datatable
    da.Fill(dt)
    app.Close()


    If dt.Rows.Count > 0 Then
    txtID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(10, CChar("A"))
    Else
    txtID.Text = "1".PadLeft(10, CChar("A"))
    End If
    End Sub



    Private Function getLastNumber() As Integer


    Dim cnn1 As New OleDb.OleDbConnection
    cnn1.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=mydataX.mdb;"
    If Not cnn1.State = ConnectionState.Open Then
    'open connection
    cnn1.Open()
    End If


    Dim da As New OleDb.OleDbDataAdapter("select top 1 cid from checker order by cid desc;", cnn1)
    Dim dt As New DataTable
    'fill data to datatable
    da.Fill(dt)
    cnn1.Close()


    If dt.Rows.Count > 0 Then
    Return CInt(Val(dt.Rows(0)(0)))
    End If
    Return 0
    End Function


    Click image for larger version. 

Name:	a.PNG 
Views:	17 
Size:	3.8 KB 
ID:	39305Click image for larger version. 

Name:	b.PNG 
Views:	17 
Size:	4.7 KB 
ID:	39306
    the textbox after user success key in data it should be auto change to BBBBBBBB37 but it fail to change

    Below is a new code i create for auto id

    Private Sub Number()
    Dim ids As List(Of Integer) = New List(Of Integer)()
    For i As Integer = 1 To 100
    ids.Add(i)
    Next


    Dim idstring As String = "INV" & ids(count).ToString().PadLeft(4, "0"c)
    txtID.Text = idstring
    count += 1
    End Sub
    Last edited by christing; 08-04-2019 at 11:28 PM.

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Hmm, well why not use a simple DMax()+1 in the Before_Update of the Form? Just seems like a lot of code just to get the next number.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-12-2017, 12:41 AM
  2. Use a Query to generate auto ID
    By banpreet in forum Queries
    Replies: 2
    Last Post: 07-28-2016, 01:28 PM
  3. Replies: 5
    Last Post: 09-05-2012, 06:42 PM
  4. Display PASS or FAIL using Unbound textbox
    By Shambler2 in forum Reports
    Replies: 7
    Last Post: 06-02-2011, 11:19 AM
  5. Auto Generate Record
    By mjhopler in forum Forms
    Replies: 2
    Last Post: 02-10-2010, 03:40 PM

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