Hello DataMiser, Thank you for your advice and your hard work reall i got amazed by you. Every things work fine but I'm facing problem after I made your recommendation as well, when entered blocks code work like charm, but when sell blocks, TxBlock reset, For example: If I entered 3 blocks and Txcount should be 4 when close form, Now when I sell block 1 to dealer and return back to continue entered blocks i found that Txcount = 2 and in fact it should be 4 or if sell block 2 Txcount = 3. As you can see in below attachment. Any advice please? Thank you in Advance
I think we need to add some line to Load Form to prevent this issue.
Code:
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
Code to enerted block mention below.
Code:
Private Sub txtICCID_KeyPress(KeyAscii As Integer)
'This check that all information has been entered and the saves the record
Dim Nm As Double
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.Find "number = '" & txtICCID.Text & "'"
If rsReceived.EOF Then
rsReceived.AddNew
rsReceived.Fields(0) = txtICCID.Text
rsReceived.Fields(1) = TxBlock.Text
rsReceived.Fields(3) = dtpReceived.Value
rsReceived.Fields(2) = 0 ' CmActiveAgent.Text : Dealer Name
rsReceived.Fields(4) = 0 ' dtpReceived : Sell Date
rsReceived.Fields(5) = 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
txtICCID.SetFocus
End If
Else
MsgBox "Repeated"
txtICCID.Text = ""
End If
Else
txtICCID.Text = ""
MessageBoxH Me.hwnd
MsgBox "please enter 11 or 12 number!", vbCritical + vbMsgBoxRtlReading + vbMsgBoxRight, "Warning"
Call OffMsg
End If
End If
Exit Sub
End Sub
Code to Sell blocks as below described:
Code:
Private Sub CmdSell_Click()
If TxActiveBlock.Text <> "" And CmActiveAgent.Text <> "" Then
rsReceived.Filter = "DealerName='" & CmActiveAgent.Text & "'"
rsReceived.Filter = "BlockNo=" & TxActiveBlock.Text
If rsReceived.RecordCount <> 0 Then
rsReceived.MoveFirst
Do While Not rsReceived.EOF
rsReceived.Fields(2) = CmActiveAgent.Text
rsReceived.Fields(4) = dtpReceived
rsReceived.Update
rsReceived.MoveNext
Loop
MsgBox "Block Sell"
End If
'CmdBlock.Enabled = False
TxActiveBlock.Text = ""
CmActiveAgent.Text = ""
Else
MsgBox "Please chose block and dealer name"
End If
End Sub
Code:
Private Sub CmActiveBlock_GotFocus()
Dim Tx
CmActiveBlock.Clear
Set City_str = New Recordset
City_str.Open "SELECT DISTINCT BlockNo, DealerName FROM TbStore", dbContact, adOpenStatic, adLockOptimistic
City_str.Filter = "DealerName=0"
If City_str.RecordCount <> 0 Then
Tx = 0
Do While Not City_str.EOF
If Tx <> City_str.Fields("BlockNo") Then CmActiveBlock.AddItem City_str.Fields("BlockNo")
Tx = City_str.Fields("BlockNo")
City_str.MoveNext
Loop
End If
End Sub
Edited: Dear DataMiser, I apologize, I do have this problem before i made your update. Looking forward for your advice. Thank you