Rich_Lovina
Registered User.
- Local time
- Tomorrow, 10:40
- Joined
- Feb 27, 2002
- Messages
- 224
I have a form with an AutoFillNewRecs, which was tied to a table. Now i TIED IT TO A QUERY, and the formfields tied to the related tables cannot accept a new entry for a new record.
We get the message :
You can't change this field until you save the record.
And if I try to save the record it says my field is null, and I can't have a null value there??
Note: This message only occurs on fields now tied to a table and they are many-sided entries to the one-side table.
I believe the code must change or sthing in properties. I fixed this once before but cant remember how.
Anyone experience this?
Tks in advance.
Here's the code which was working:
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 = ";" & F![AutoFillNewRecordFields] & ";"
' 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
DoCmd.RunCommand acCmdSaveRecord
F.Painting = True
End Function
We get the message :
You can't change this field until you save the record.
And if I try to save the record it says my field is null, and I can't have a null value there??
Note: This message only occurs on fields now tied to a table and they are many-sided entries to the one-side table.
I believe the code must change or sthing in properties. I fixed this once before but cant remember how.
Anyone experience this?
Tks in advance.
Here's the code which was working:
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 = ";" & F![AutoFillNewRecordFields] & ";"
' 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
DoCmd.RunCommand acCmdSaveRecord
F.Painting = True
End Function