Thanks Bruce,
I appreciate any help you or anyone else can give me on this.
Robbie
tblToFromCop
Id Autonumber p
IOCYear f
IOCNumber f
ContactID f
ContactTypeID f
tlkpContact
ContactID Autonumber p
FirstNam
LastNam
etc.
tlkpContactTyp
ContactTypeID Autonumber p
ContactTyp
tblIOCLo
IOCYear p
IOCNumber p
IOCDat
Subjec
etc.
Subforms sfmTo and sfmCopy (record source – tblToFromCopy) have a multiselect listbox to choose values from tlkpContacts
Form fmDataEntry has a record source of tblIOCLo
Subform sfmFrom (record source – tblToFromCopy) has a listbox (not multiselect) and a hidden textbox with default value from tlkpContactType.
My code:
Private Sub Form_Open(Cancel As Integer
DoCmd.GoToRecord , , acNewRe
Me.IOCYear = Year(Date
Me.IOCNumber = Nz(DMax("[IOCNumber]", "[tblIOCLog]", ""), 0) +
Me.IOCDate = Dat
End Su
Private Sub sfmCopy_Exit(Cancel As Integer
Dim db As DAO.Databas
Dim rst As DAO.Recordse
Dim i As Intege
Set db = CurrentDb(
Set rst = db.OpenRecordset("tblToFromCopy", DB_OPEN_DYNASET
For i = 0 To Form_sfmCopy.lstCC.ListCount -
If Form_sfmCopy.lstCC.Selected(i) The
rst.AddNe
rst!IOCYear = Me.IOCYea
rst!IOCNumber = Me.IOCNumbe
rst!ContactID = Form_sfmCopy.lstCC.Column(0, i
rst!ContactTypeID =
rst.Updat
'Form_sfmCopy.lstCC.Selected(i) = False 'clears the selectio
End I
Next
End Su
Private Sub sfmTo_Exit(Cancel As Integer
Dim db As DAO.Databas
Dim rst As DAO.Recordse
Dim i As Intege
Set db = CurrentDb(
Set rst = db.OpenRecordset("tblToFromCopy", DB_OPEN_DYNASET
For i = 0 To Form_sfmTo.lstTo.ListCount -
If Form_sfmTo.lstTo.Selected(i) The
rst.AddNe
rst!IOCYear = Me.IOCYea
rst!IOCNumber = Me.IOCNumbe
rst!ContactID = Form_sfmTo.lstTo.Column(0, i
rst!ContactTypeID =
rst.Updat
'Form_sfmTo.lstTo.Selected(i) = False 'clears the selectio
End I
Next
End Su
Sample values I get in tblToFromCopy when one value is selected from each subform AND I don’t set IOCYear and IOCNumber in the multiselect code above (I expect 3 records):
1st record 2nd record 3rd record 4th recor
I
IOCYear 2004
IOCNumber 1
ContactID 12 13 2
ContactTypeID 1 2
tblIOCLog will have a record IOCYear 2004, IOCNumber 1 .
----- Bruce M. Thompson wrote: ----
This is exactly the question I have posted over the last few days
So, how do you get around that blank record
The blank row I am referring to does not contain any data, therefore it is not
"blank record", but rather a placeholder for a new record
The record I ge
includes the pk as well as two fks from the table the main form i
based on, but empty fields for the data I wish to enter from th
subform
If the primary key field in the subform is an autonumber type and contains
value, then a record in that row has been started. If it is not an autonumber
is it possible that there are "default" values set for those controls in th
design of the form? If that is the case, and those default values are equal t
the the values of "the pk as well as two fks from the table the main form i
based on" then I would presume that this row is, too, just a placeholder. If th
subform's record selectors are turned on and the record selector for thi
"blank" row contains an asterisk (*), then it is merely a placeholder and not a
actual record.
So I end up with one record as described and then multiple
records with no data (fk) from the main form and the data I enter
from the subform. I am populating programatically the main form data
into the records missing that, but what do I do with that other record??
If you are ending up with multiple records in your subform (per main form
record) that contain blank fields then I would look at your code for problems.
If you want someone else to look at the code for/with you, simply post the code
for others to review and the source of your problem may be brought to light.