Code not working for text duplication to new record

C

Connie

Hi all,
In a previous question, I asked for help with dupliating certain fields in a
form. I received a great answer and am trying my best to sort throught the
code that it takes to make the duplication happen.

I am using Access 2002 and when users press a command button the address
information is supposed to duplicate in a new record. Here is the code that
was offered up as a solution. I have included the field names that I want to
be filled with duplicate data. What is happening is that only 2 of the
fields are populating...the phone number and the street identifier. Just a
note...I will never want all of the fields duplicated, only those listed.

Can anyone tell me what I am doing wrong?

Thanks in advance! Here's the code:

Option Compare Database

Option Explicit
Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

On Error Resume Next

' Exit if not on the new record.
If Not F.NewRecord Then Exit Function

' Goto the last record of the form recordset (to autofill form).
Set RS = F.RecordsetClone
RS.MoveLast

' Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function

' Get the list of fields to autofill.
FillFields =
"Name2;CONTACTPhone;StNumber;RRPO;StName;StIdentifier;City;Province;PostalCode;EmailAddress;WebSite
& F![AutoFillNewRecordFields] &
Name2;CONTACTPhone;StNumber;RRPO;StName;StIdentifier;City;Province;PostalCode;EmailAddress;WebSite"

' If there is no criteria field, then set flag indicating ALL
' fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

' Visit each field on the form.
For Each C In F
' Fill the field if ALL fields are to be filled OR if the
' ...ControlSource field can be found in the FillFields list.
If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next
F.Painting = True

End Function
 
M

mscertified

Check that the names of the controls on your form are the same as the names
being referred to in the code.

-Dorian
 
C

Connie

Thanks for your reply...yes they are the same. I was able to get some to
duplicate while other still will not. I have checked and double checked the
names but still no go.

mscertified said:
Check that the names of the controls on your form are the same as the names
being referred to in the code.

-Dorian

Connie said:
Hi all,
In a previous question, I asked for help with dupliating certain fields in a
form. I received a great answer and am trying my best to sort throught the
code that it takes to make the duplication happen.

I am using Access 2002 and when users press a command button the address
information is supposed to duplicate in a new record. Here is the code that
was offered up as a solution. I have included the field names that I want to
be filled with duplicate data. What is happening is that only 2 of the
fields are populating...the phone number and the street identifier. Just a
note...I will never want all of the fields duplicated, only those listed.

Can anyone tell me what I am doing wrong?

Thanks in advance! Here's the code:

Option Compare Database

Option Explicit
Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

On Error Resume Next

' Exit if not on the new record.
If Not F.NewRecord Then Exit Function

' Goto the last record of the form recordset (to autofill form).
Set RS = F.RecordsetClone
RS.MoveLast

' Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function

' Get the list of fields to autofill.
FillFields =
"Name2;CONTACTPhone;StNumber;RRPO;StName;StIdentifier;City;Province;PostalCode;EmailAddress;WebSite
& F![AutoFillNewRecordFields] &
Name2;CONTACTPhone;StNumber;RRPO;StName;StIdentifier;City;Province;PostalCode;EmailAddress;WebSite"

' If there is no criteria field, then set flag indicating ALL
' fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

' Visit each field on the form.
For Each C In F
' Fill the field if ALL fields are to be filled OR if the
' ...ControlSource field can be found in the FillFields list.
If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next
F.Painting = True

End Function
 

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