Results 1 to 14 of 14

Thread: [RESOLVED] [Urgent] Please help me

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Resolved [RESOLVED] [Urgent] Please help me

    Hello Folk, I have code below it's work but not as it should be. I entered 100 record for each block and blockno generated Auto and rising up but sometimes blockno not working and it's crazy for example when reach block 20 and close form and re-open it block write block 13 and sometimes 10? I did mass up with my data. Is there any way to perform code below and let always record [ Bk + 1 ] when finish entered 100 recordset please? I'm looking forward for your advice.

    Edited: Add Form.

    Code:
    Const BlockSize = 100
    Dim rsReceived As ADODB.Recordset
    Dim cn As Long, Tn As Long, Bn As Long, Bk As Long
    '------------------------------------------------------------------------
    Private Sub Form_Load()
    'This opens the recordset
    Set rsReceived = New ADODB.Recordset
    rsReceived.Open "Select * From TbStore", dbContact, adOpenStatic, adLockOptimistic
    dtpReceived.Value = Date
    
    cn = 0
    
    If rsReceived.RecordCount > 0 Then
        rsReceived.MoveLast
        cn = rsReceived.RecordCount Mod 100
        If cn > 0 Then 'Is not evenly divisible by 100
    
            TxBlock.Text = Format(rsReceived.Fields("BlockNo"), "#,##")
            TxTotal.Text = Format(rsReceived.RecordCount, "#,##")
        Else
            TxBlock.Text = Format(rsReceived.Fields("BlockNo") + 1, "#,##")
            TxTotal.Text = Format(rsReceived.RecordCount, "#,##")
        End If
    Else
        TxBlock.Text = 0
        TxTotal.Text = 0
    End If
      Bk = TxBlock.Text
      Tn = TxTotal.Text
      TxCount.Text = 0
    
    End Sub
    '-----------------------------------------------------------------------------------------
    Private Sub txtICCID_KeyPress(KeyAscii As Integer)
    'This check that all information has been entered and the saves the record
    
    Dim Nm As Double
    
    Select Case KeyAscii
        Case 8, 13, 46 To 57
        Case Else
            KeyAscii = 0
            MsgBox "Only A to Z allowed"
    End Select
    
      If KeyAscii = 13 And Not txtICCID.Locked Then
       If Len(txtICCID.Text) = 11 Or Len(txtICCID.Text) = 12 Then
          Nm = txtICCID.Text
          txtICCID.Text = Nm
    
          If Bk = 0 Then Bk = 1
          TxBlock.Text = Format(Bk, "#,##")
          
        rsReceived.Filter = "Number =" & Nm
       If rsReceived.RecordCount = 0 Then
    
    rsReceived.AddNew
    
       rsReceived.Fields(0) = txtICCID.Text
       rsReceived.Fields(1) = TxBlock.Text
       rsReceived.Fields(3) = dtpReceived.Value
       rsReceived.Fields(2) = 0
       rsReceived.Fields(4) = 0
       rsReceived.Fields(5) = 0
       rsReceived.Fields(6) = 0
       rsReceived.Update
    
    cn = cn + 1
            TxCount.Text = cn
            txtICCID.Text = ""
            txtICCID.SetFocus
            If cn = BlockSize Then
              Bk = Bk + 1
              MsgBox "Block Done"
              txtICCID.Locked = True
              cn = 0
              txtICCID.Locked = False
              TxCount.Text = cn
              txtICCID.SetFocus
              txtICCID.Text = ""
            End If
              Else
           MsgBox "Number Exist"
           txtICCID.Text = ""
       End If
        Else
          txtICCID.Text = ""
          MessageBoxH Me.hwnd
              MsgBox "Please enter 11 0r 12 digits!", vbCritical + vbMsgBoxRtlReading + vbMsgBoxRight, "ÇÑÞÇã"
               Call OffMsg
        End If
      End If
    End Sub
    Attached Images Attached Images  
    Last edited by brss; Aug 18th, 2012 at 10:23 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
  •  



Click Here to Expand Forum to Full Width