Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 30th, 2005, 08:15 PM
campbellbrian2001@yahoo.com
Guest
 
Posts: n/a
Default Carry data over to new record...

I'm trying to get the "Carry data over to new record"
code to work from Allen Browne's site:
http://allenbrowne.com/ser-24.html
I follwed the instruction explicitly and somethings not working... any
clues?

Thanks all!!
Brian

  #2  
Old December 30th, 2005, 09:35 PM
John Welch
Guest
 
Posts: n/a
Default Re: Carry data over to new record...

Is your computer plugged in?
Seriously, though, if you just say "something's not working", no one is
going to have any idea how to help you.
Here is a link that has some tips on asking questions so that you get good
help-
http://www.mvps.org/access/netiquette.htm

-John

<campbellbrian2001@yahoo.com> wrote in message
news:1135973234.378623.272050@g43g2000cwa.googlegr oups.com...[color=blue]
> I'm trying to get the "Carry data over to new record"
> code to work from Allen Browne's site:
> http://allenbrowne.com/ser-24.html
> I follwed the instruction explicitly and somethings not working... any
> clues?
>
> Thanks all!!
> Brian
>[/color]


  #3  
Old December 30th, 2005, 09:45 PM
campbellbrian2001@yahoo.com
Guest
 
Posts: n/a
Default Re: Carry data over to new record...

Sorry!
Here's what I did..
Open a new form in Design View with 4 text boxes bound to 4 fields in a
table.
In the Properties Box, selected the BeforeInsert event, and typed in
[Event Procedure]
"Call CarryOver(Me)"
Created a module "basCarryOver" and typed this code:

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 record selector gives a new record but without the text boxes
pre-filled with the last record's values.

Thanks! Brian

  #4  
Old December 31st, 2005, 12:25 AM
John Welch
Guest
 
Posts: n/a
Default Re: Carry data over to new record...

Ok, that's better. Does your event procedure look like this:

Private Sub Form_BeforeInsert(Cancel As Integer)
Call CarryOver(Me)
End Sub

And are the names of your textboxes exactly the same as the fields they are
bound to?

It's not clear if the function is getting called at all (being able to go to
a new record with the record selector isnt proof), so you could put this
line:
msgbox "Carry Over was called"
after the dim statements in the CarryOver procedure to make sure it got
called.

hope this helps
-John

<campbellbrian2001@yahoo.com> wrote in message
news:1135978433.274746.62200@g44g2000cwa.googlegro ups.com...[color=blue]
> Sorry!
> Here's what I did..
> Open a new form in Design View with 4 text boxes bound to 4 fields in a
> table.
> In the Properties Box, selected the BeforeInsert event, and typed in
> [Event Procedure]
> "Call CarryOver(Me)"
> Created a module "basCarryOver" and typed this code:
>
> 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 record selector gives a new record but without the text boxes
> pre-filled with the last record's values.
>
> Thanks! Brian
>[/color]


  #5  
Old December 31st, 2005, 02:35 AM
Lyle Fairfield
Guest
 
Posts: n/a
Default Re: Carry data over to new record...

I like to use

With DoCmd
.RunCommand acCmdSelectRecord
.RunCommand acCmdCopy
.RunCommand acCmdPasteAppend
End With

called with a Command Button's OnClick or a PopUp Menu Selection.

This permits "carrying" the values of any record, not just the last
entered or showing. More clicks are not required as the button creates
a new record with just one click.
One can have problems with unique indexes / primary keys / counters but
if one thinks things out carefully these can be overcome.

  #6  
Old December 31st, 2005, 02:55 AM
Allen Browne
Guest
 
Posts: n/a
Default Re: Carry data over to new record...

To help you debug your code,
1. Check that it compiles okay, by choosing Compile on the Debug menu.

2. Temporarily comment out the error handler, by adding a single quote to
the first line:
'On Error GoTo Err_CarryOver

3. Immedately below that, enter:
Stop

Now when the code runs, it will stop and highlight the Stop line. You can
then press F8 to single-step through the code, and see what is happening
until you identify the problem.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<campbellbrian2001@yahoo.com> wrote in message
news:1135978433.274746.62200@g44g2000cwa.googlegro ups.com...[color=blue]
> Sorry!
> Here's what I did..
> Open a new form in Design View with 4 text boxes bound to 4 fields in a
> table.
> In the Properties Box, selected the BeforeInsert event, and typed in
> [Event Procedure]
> "Call CarryOver(Me)"
> Created a module "basCarryOver" and typed this code:
>
> 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 record selector gives a new record but without the text boxes
> pre-filled with the last record's values.
>
> Thanks! Brian
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles