1,105,332 Community Members

auto generate numbers

Member Avatar
Yousha
Newbie Poster
13 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a data base using access which has one column as jobno and which is empty. I want that when my form load (vb.net 2005) it generate a number which then appears in a textbox.

Below are my codes please i cant complete it help me.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sql As String
Dim strjobno As String = TextBox18.Text
Dim Cn As OleDb.OleDbConnection
Dim myCom As OleDb.OleDbCommand
Cn = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Hardware.mdb")
Cn.Open()
sql = "select MAX(jobno) from repair"
myCom = New OleDb.OleDbCommand(sql, Cn)
Cn.Close()
If strjobno Is DBNull.Value Then
Dim intjobno As Integer = Convert.ToInt32(strjobno)
strjobno = 1
Else
strjobno = +1
End If
MyTextBox18.Text =
End Sub

Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
1
 

see if this help :

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sql As String
        Dim strjobno As String
        Dim Cn As OleDb.OleDbConnection
        Dim myCom As OleDb.OleDbCommand

        Cn = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Hardware.mdb")
        Cn.Open()
        sql = "sselect MAX(jobno) from repair"
        myCom = New OleDb.OleDbCommand(sql, Cn)
        strjobno = myCom.ExecuteScalar
        Cn.Close()
        If strjobno Is DBNull.Value Then
            Dim intjobno As Integer = Convert.ToInt32(strjobno)
            strjobno = 1
        Else
            strjobno = strjobno + 1
        End If
        TextBox1.Text = strjobno
    End Sub

if your code already completed then please mark this thread as Solved.

Member Avatar
Netcode
Veteran Poster
1,049 posts since Jun 2009
Reputation Points: 33 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 8 [?]
 
0
 
Private Sub New_User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'declare variables
      Dim randomvalue As New Random   'create random object
      Dim randomhold As Integer
  
   'generate random number
            For i As Integer = 0 To 9999
                randomhold = randomvalue.Next(1, 9999) + DateTime.Now.Minute +                  DateTime.Now.Year
                txtUserId.Text = randomhold
            Next
End Sub
Member Avatar
Luc001
Posting Pro in Training
455 posts since Mar 2010
Reputation Points: 77 [?]
Q&As Helped to Solve: 117 [?]
Skill Endorsements: 3 [?]
 
0
 

Hi chibex64,

Your code only shows a randomvalue and not the datetime.minute or datetime.year.
You should do it like this:

'declare variables
        Dim randomvalue As New Random   'create random object
        Dim randomhold As Integer

        'generate random number
        For i As Integer = 0 To 9999
            randomhold = randomvalue.Next(1, 9999)
            txtUserId.Text = randomhold & " " & DateTime.Now.Minute & "  " & DateTime.Now.Year
        Next
Member Avatar
Netcode
Veteran Poster
1,049 posts since Jun 2009
Reputation Points: 33 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 8 [?]
 
0
 

Thanks luc001. i guess it was a typo. hope it solves Yousha's problem

Member Avatar
Yousha
Newbie Poster
13 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank to all of you guys your post has help me to complete my project. I know now whatever i have a problem just come here. Thank you very much. Have a nice day.

Question Answered as of 3 Years Ago by Netcode, Luc001 and Jx_Man
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article