A
Asif
Hi
I am trying to use some code I found on Allen Browne
website to carry data across from previous record to a new
record.
I have a orders form with a orders detail subform, what I
am trying to do is set a button which will carry the data
from the previous record to the current one.
I have a button with the following code
Private Sub Command81_Click()
Call CarryOver(Me)
End Sub
and the module code is
Option Compare Database
Sub CarryOver(frm As Form)
On Error GoTo Err_CarryOver
' Purpose: Carry the values over from the last record to
a new one.
' Usage: In a form's BeforeInsert event procedure, enter:
' Call CarryOver(Me)
' Notes: This example limited to text boxes and combo
boxes.
' Text/combo boxes must have same Name as the
fields they represent.
Dim rst As DAO.Recordset
Dim ctl As Control
Dim i As Integer
Set rst = frm.RecordsetClone
If rst.RecordCount > 0 Then
rst.MoveLast
For i = 0 To frm.Count - 1
Set ctl = frm(i)
If TypeOf ctl Is TextBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
ElseIf TypeOf ctl Is ComboBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
End If
Next
End If
Exit_CarryOver:
Set rst = Nothing
Exit Sub
Err_CarryOver:
Select Case Err
Case 2448 'Cannot assign a value
Debug.Print "Value cannot be assigned to " &
ctl.Name
Resume Next
Case 3265 'Name not found in this collection.
Debug.Print "No matching field name found for " &
ctl.Name
Resume Next
Case Else
MsgBox "Carry-over values were not assigned,
from " & ctl.Name & _
". Error #" & Err.Number & ": " &
Err.Description, vbExclamation, "CarryOver()"
Resume Exit_CarryOver
End Select
End Sub
The problem is when I click on the button the following
error occurs
Run-Time error '91':
Object variable or With block variable not set
and the
MsgBox "Carry-over values were not assigned, from " &
ctl.Name & _
". Error #" & Err.Number & ": " & Err.Description,
vbExclamation, "CarryOver()"
is highligted. I am using Access 2002 and I am creating
an adp.
I hope I have explained it well and any help will be much
appreciated.
Kindest Regards
Asif
I am trying to use some code I found on Allen Browne
website to carry data across from previous record to a new
record.
I have a orders form with a orders detail subform, what I
am trying to do is set a button which will carry the data
from the previous record to the current one.
I have a button with the following code
Private Sub Command81_Click()
Call CarryOver(Me)
End Sub
and the module code is
Option Compare Database
Sub CarryOver(frm As Form)
On Error GoTo Err_CarryOver
' Purpose: Carry the values over from the last record to
a new one.
' Usage: In a form's BeforeInsert event procedure, enter:
' Call CarryOver(Me)
' Notes: This example limited to text boxes and combo
boxes.
' Text/combo boxes must have same Name as the
fields they represent.
Dim rst As DAO.Recordset
Dim ctl As Control
Dim i As Integer
Set rst = frm.RecordsetClone
If rst.RecordCount > 0 Then
rst.MoveLast
For i = 0 To frm.Count - 1
Set ctl = frm(i)
If TypeOf ctl Is TextBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
ElseIf TypeOf ctl Is ComboBox Then
If Not IsNull(rst(ctl.Name)) Then
ctl = rst(ctl.Name)
End If
End If
Next
End If
Exit_CarryOver:
Set rst = Nothing
Exit Sub
Err_CarryOver:
Select Case Err
Case 2448 'Cannot assign a value
Debug.Print "Value cannot be assigned to " &
ctl.Name
Resume Next
Case 3265 'Name not found in this collection.
Debug.Print "No matching field name found for " &
ctl.Name
Resume Next
Case Else
MsgBox "Carry-over values were not assigned,
from " & ctl.Name & _
". Error #" & Err.Number & ": " &
Err.Description, vbExclamation, "CarryOver()"
Resume Exit_CarryOver
End Select
End Sub
The problem is when I click on the button the following
error occurs
Run-Time error '91':
Object variable or With block variable not set
and the
MsgBox "Carry-over values were not assigned, from " &
ctl.Name & _
". Error #" & Err.Number & ": " & Err.Description,
vbExclamation, "CarryOver()"
is highligted. I am using Access 2002 and I am creating
an adp.
I hope I have explained it well and any help will be much
appreciated.
Kindest Regards
Asif