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

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.

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

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.