Inserting specific number of records

G

Guest

I have a Data Entry form in which the user have to insert a specific numbrer
of record, depending on the type of product he choose. Ej: The product "A"
have to have 3 data, so it will need to insert 3 record on the table only, no
more.

I have created a simple code in VB that I supose to have to restrcit the
number of record records, depending on a Textbox value

****************************************
CODE
****************************************
Private Sub LECTURA_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Lectura
Dim Respuesta
If Form.CurrentRecord <= Forms!lecturas!TXTMuestras Then
If Val(LECTURA) = 0 Then
MsgBox "Value can not be a zero", vbOKCancel + vbCritical, "Zero
value!"
Cancel = True
Else
ID_SKU = "00329"
ID_LECTURA = 1
NO_LINEA = Form.CurrentRecord
End If
Else
Respuesta = MsgBox("You has reached the maximun number of samples
for this product" & vbCrLf & _
"Verify samples please.", vbCritical + vbOKOnly,
"Reading samples")
Cancel = True
End If
Exit_Lectura:
Exit Sub
Err_Lectura:
MsgBox Err.Description
Resume Exit_Lectura
End Sub

*************************************
End code
*************************************

The problem I am having is the crusor. It moves to the next record after the
maximum value for a specific product have been reached.

Thanks in advance,
 
A

Arvin Meyer [MVP]

You could do something like this (aircode):

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim rst As DAO.Recordset

Set rst = Me.RecordsetClone
If rst.RecordCount > 0 Then
rst.MoveLast
Else
rst.OpenRecordset
End If
If rst.RecordCount > 2 Then
Cancel = True
MsgBox "You are only allowed to enter 3 records!"
End If

rst.Close
Set rst = Nothing
End Sub
 
G

Guest

Thanks Arvin.
--
César Parrales


Arvin Meyer said:
You could do something like this (aircode):

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim rst As DAO.Recordset

Set rst = Me.RecordsetClone
If rst.RecordCount > 0 Then
rst.MoveLast
Else
rst.OpenRecordset
End If
If rst.RecordCount > 2 Then
Cancel = True
MsgBox "You are only allowed to enter 3 records!"
End If

rst.Close
Set rst = Nothing
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top