473,563 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add record to Subform when not on Mainform

Bob
Hi Everybody

I have a form called frmListBox that is connected to a table tblListBox.

This is opened from a form called "frmInvoiceOrde r" which has a subform called "zfrmInvoiceOrd er"
and floats above (ie is pop-up) [frmInvoiceOrder]![zfrmInvoiceOrde r]

Private Sub ListBox_DblClic k(Cancel As Integer)
DoCmd.OpenForm "Forms![frmInvoiceOrder]![zfrmInvoiceOrde r", , , , acFormAdd

Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtCreatedDate] = Me!ListBox.Colu mn(1)
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtCreatedTime] = Me!ListBox.Colu mn(2)
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtFrom] = Me!ListBox.Colu mn(3)
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtTo] = Me!ListBox.Colu mn(4)
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![MemoContents] = Me!ListBox.Colu mn(5)
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtEbay#] = Me!ListBox.Colu mn(6)
End Sub

Although all of the fields copy from "frmListBox " to "Forms![frmInvoiceOrder]![zfrmInvoiceOrde r" OK
I cannot get it to add a new record to/in the subform before it copies the record.

The 2 main errors I get are:

error 2012 trying to refer to a form that doesn't exist.
error 2489 - The object 'Forms![frmInvoiceOrder]![zfrmInvoiceOrde r' isn't open). but when I get this
error message, the subform is indeed open - i'm looking right at it!

It seems to me that although the subform is open "inside" the Mainform, Access 2000 doesn't
consider it to be open. Just viewable.

I did consider making an intermediate form and do it from there. I have done somethong similar
before. But this would be an untidy work around

If anyone could help I be most grateful.

Regards Smiley Bob
Nov 13 '05 #1
5 3362
The main form frmInvoiceOrder is open *and* has a record at this point? If
it does not have a record, the attempt to create a *related* record in the
subform may fail.

Your middle paragraph that says the fields copy ok though it does not create
the record. If the fields copy (i.e. you see these values turn up the
subform), but the record is not added? This suggests that the code is
working, but there is another cause why the record is not saved, e.g. there
is another field that is required, but no value is entered.

Then the next paragraph suggests Access is having trouble finding the
object. Unless the main form has been closed by this stage, this may
indicate a Name AutoCorrect problem. See:
http://allenbrowne.com/bug-03.html

Subforms are never open in their own right, i.e. zfrmInvoiceOrde r itself is
not part of the Forms collection. You appear to be using the correct
reference though, through the main form, and referring to the Form in the
subform control. You could double-check that the subform *control* is named
zfrmInvoiceOrde r, regardless of the name of the form that gets loaded into
the control (its SourceObject).

This approach may help to pinpoint where the error is occurring:
Dim frm As Form
Set frm = Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form
With Me.ListBox
frm!txtCreatedD ate = .Column(1)
frm!txtCreatedT ime = .Column(2)
End With
Set frm = Nothing

Hopefully you don't really have a control named ListBox, as that is a
reserved word in VBA.

--
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.

"Bob" <sm*******@hotm ail.com> wrote in message
news:ps******** *************** *********@4ax.c om...

I have a form called frmListBox that is connected to a table tblListBox.

This is opened from a form called "frmInvoiceOrde r" which has a subform called "zfrmInvoiceOrd er" and floats above (ie is pop-up) [frmInvoiceOrder]![zfrmInvoiceOrde r]

Private Sub ListBox_DblClic k(Cancel As Integer)
DoCmd.OpenForm "Forms![frmInvoiceOrder]![zfrmInvoiceOrde r", , , , acFormAdd
Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtCreatedDate] = Me!ListBox.Colu mn(1) Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtCreatedTime] = Me!ListBox.Colu mn(2) Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtFrom] = Me!ListBox.Colu mn(3) Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtTo] = Me!ListBox.Colu mn(4) Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![MemoContents] = Me!ListBox.Colu mn(5) Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form![txtEbay#] = Me!ListBox.Colu mn(6) End Sub

Although all of the fields copy from "frmListBox " to "Forms![frmInvoiceOrder]![zfrmInvoiceOrde r" OK I cannot get it to add a new record to/in the subform before it copies the record.
The 2 main errors I get are:

error 2012 trying to refer to a form that doesn't exist.
error 2489 - The object 'Forms![frmInvoiceOrder]![zfrmInvoiceOrde r' isn't open). but when I get this error message, the subform is indeed open - i'm looking right at it!

It seems to me that although the subform is open "inside" the Mainform, Access 2000 doesn't consider it to be open. Just viewable.

I did consider making an intermediate form and do it from there. I have done somethong similar before. But this would be an untidy work around

If anyone could help I be most grateful.

Regards Smiley Bob

Nov 13 '05 #2
Bob
On Thu, 10 Jun 2004 10:11:30 +0800, "Allen Browne" <Al*********@Se eSig.Invalid> wrote:
The main form frmInvoiceOrder is open *and* has a record at this point? If
it does not have a record, the attempt to create a *related* record in the
subform may fail. I dont think this is the problem. frmInvoiceOrder]![zfrmInvoiceOrde r is open with the next record's
ID# in the subform showing ready to go.
Your middle paragraph that says the fields copy ok though it does not create
the record. If the fields copy (i.e. you see these values turn up the
subform), but the record is not added? This suggests that the code is
working, but there is another cause why the record is not saved, e.g. there
is another field that is required, but no value is entered.
At the moment it just overwrites the existing record
Then the next paragraph suggests Access is having trouble finding the
object. Unless the main form has been closed by this stage, this may
indicate a Name AutoCorrect problem. See:
http://allenbrowne.com/bug-03.html

That is turned off

I have re arranged the code to this more shorthand way,
but I am still getting the problem that when I try to do anything with it, the code fails.

Private Sub ListOtherEmails _DblClick(Cance l As Integer)
Dim frm As Form
Set frm = Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form
With Me.ListOtherEma ils

DoCmd.GoToRecor d acDataForm, ["frm"], acNewRec, [offset]
<sticking Here, Ms Access can't find the field "|" referred to in your expression>

frm![txtCreatedDate] = Me!ListOtherEma ils.Column(1)
frm![txtCreatedTime] = Me!ListOtherEma ils.Column(2)
frm![txtFrom] = Me!ListOtherEma ils.Column(3)
frm![txtTo] = Me!ListOtherEma ils.Column(4)
frm![MemoContents] = Me!ListOtherEma ils.Column(5)

End With
Set frm = Nothing
end sub

Thanks for giving my Problem your attention

Smiley Bob

Nov 13 '05 #3
Ah, so you are getting a record overwritten, instead of appended?

It would be possible to set focus to the main form, the subform control, and
then a control in the subform, and then RunCommand acCmdRecordsGot oNew to
get you to a new record before you try assigning the values. However, it may
be easier to write the record to the RecordsetClone of the subform instead.

You will need to pick up the primary key value from the main form, and
assign it to your foreign key field in the subform. Then you will be writing
to the fields in the subform's Recordset (which may have different names
than the controls on the subform). Something like this:

Dim frm As Form
Dim rs As DAO.Recordset
Set frm = Forms![frmInvoiceOrder]
If frm.NewRecord Then
MsgBox "Select a record in the main form first."
Else
Set rs = frm![zfrmInvoiceOrde r].Form.Recordset Clone
rs.AddNew
With Me.ListBox
rs![YourForeignKeyF ieldHere] = frm![YourPrimaryKeyF ieldHere]
rs!txtCreatedDa te = .Column(1)
rs!txtCreatedTi me = .Column(2)
'and so on.
End With
rs.Update
End If
Set rs = Nothing
Set frm = Nothing
--
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.

"Bob" <sm*******@hotm ail.com> wrote in message
news:it******** *************** *********@4ax.c om...
On Thu, 10 Jun 2004 10:11:30 +0800, "Allen Browne" <Al*********@Se eSig.Invalid> wrote:
The main form frmInvoiceOrder is open *and* has a record at this point? Ifit does not have a record, the attempt to create a *related* record in thesubform may fail. I dont think this is the problem. frmInvoiceOrder]![zfrmInvoiceOrde r is

open with the next record's ID# in the subform showing ready to go.

Your middle paragraph that says the fields copy ok though it does not createthe record. If the fields copy (i.e. you see these values turn up the
subform), but the record is not added? This suggests that the code is
working, but there is another cause why the record is not saved, e.g. thereis another field that is required, but no value is entered.
At the moment it just overwrites the existing record

Then the next paragraph suggests Access is having trouble finding the
object. Unless the main form has been closed by this stage, this may
indicate a Name AutoCorrect problem. See:
http://allenbrowne.com/bug-03.html

That is turned off

I have re arranged the code to this more shorthand way,
but I am still getting the problem that when I try to do anything with it,

the code fails.
Private Sub ListOtherEmails _DblClick(Cance l As Integer)
Dim frm As Form
Set frm = Forms![frmInvoiceOrder]![zfrmInvoiceOrde r].Form
With Me.ListOtherEma ils

DoCmd.GoToRecor d acDataForm, ["frm"], acNewRec, [offset]
<sticking Here, Ms Access can't find the field "|" referred to in your expression>
frm![txtCreatedDate] = Me!ListOtherEma ils.Column(1)
frm![txtCreatedTime] = Me!ListOtherEma ils.Column(2)
frm![txtFrom] = Me!ListOtherEma ils.Column(3)
frm![txtTo] = Me!ListOtherEma ils.Column(4)
frm![MemoContents] = Me!ListOtherEma ils.Column(5)

End With
Set frm = Nothing
end sub

Thanks for giving my Problem your attention

Smiley Bob

Nov 13 '05 #4
Bob

Hi Allen

Thanks for the attention you are giving my problem. I feel now that I am close to solving it now.

Private Sub ListOtherEmails _DblClick(Cance l As Integer)

Dim frm As Form
Dim rs As DAO.Recordset
Set frm = Forms!frmInvoic eOrder
If frm.NewRecord Then
MsgBox "Select a record in the main form first."
Else
Set rs = frm![zfrmInvoiceOrde r].Form.Recordset Clone
rs.AddNew
With Me.ListOtherEma ils
rs![InvoiceOrderID] = frm![InvoiceOrderID]

'Code runs OK down to here. It even creates a new record on the subform, which is something I
'haven't been able to do before.

'However, it is now faulting on the next 5 lines error 3625 Item "Item not found in this collection"

rs!txtCreatedDa te = Me!ListOtherEma ils.Column(1)
rs!txtCreatedTi me = Me!ListOtherEma ils.Column(2)
rs!txtFrom = Me!ListOtherEma ils.Column(3)
rs!txtTo = Me!ListOtherEma ils.Column(4)
rs!MemoContents = Me!ListOtherEma ils.Column(5)

' If I comma the above 5 lines out It creates new blank subform records

End With
rs.Update
End If
Set rs = Nothing
Set frm = Nothing

End Sub

Regards Smiley Bob

Nov 13 '05 #5
What is the name of the *field* (not text box)?

Perhaps it is "CreatedDat e", in which case you would need:
rs!CreatedDate = Me!ListOtherEma ils.Column(1)

--
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.

"Bob" <sm*******@hotm ail.com> wrote in message
news:ek******** *************** *********@4ax.c om...

Hi Allen

Thanks for the attention you are giving my problem. I feel now that I am close to solving it now.
Private Sub ListOtherEmails _DblClick(Cance l As Integer)

Dim frm As Form
Dim rs As DAO.Recordset
Set frm = Forms!frmInvoic eOrder
If frm.NewRecord Then
MsgBox "Select a record in the main form first."
Else
Set rs = frm![zfrmInvoiceOrde r].Form.Recordset Clone
rs.AddNew
With Me.ListOtherEma ils
rs![InvoiceOrderID] = frm![InvoiceOrderID]

'Code runs OK down to here. It even creates a new record on the subform, which is something I 'haven't been able to do before.

'However, it is now faulting on the next 5 lines error 3625 Item "Item not found in this collection"
rs!txtCreatedDa te = Me!ListOtherEma ils.Column(1)
rs!txtCreatedTi me = Me!ListOtherEma ils.Column(2)
rs!txtFrom = Me!ListOtherEma ils.Column(3)
rs!txtTo = Me!ListOtherEma ils.Column(4)
rs!MemoContents = Me!ListOtherEma ils.Column(5)

' If I comma the above 5 lines out It creates new blank subform records

End With
rs.Update
End If
Set rs = Nothing
Set frm = Nothing

End Sub

Regards Smiley Bob

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3729
by: kimj.dk | last post by:
Hi, I have a form with a subform where the subform uses the value from a combo box on the main form as a query criteria. I don't want the subform to update or get data before the user has selected a value in the combo box because the subquery takes a while to update. Is it possible to disable the subform to update when the form loads? Best...
18
3592
by: Robert Jacobs | last post by:
Please advise... I currently have a Mainform (Customers) and a Subform (Service Requests) with a one to many relationship (one customer, many service requests) with a CustomerID that is unique for each customer and is autofilled on the subform. Subform contains field called TicketID (which there could be multiple instances of and is not...
4
2030
by: rczuba | last post by:
Problem: Creating a Default Value for a field in a subform when a field in the subform & form match. I'm trying to create a payroll database for a small home business that I have that has had (and hopefully will continue to have) lots of growth. I have created a Transaction table to hold the hours, date, location of work (as the employees...
1
1995
by: Rosy | last post by:
I have a form "A" that is set on table vessel names. I have subform "B" that is set on table vessel info. I want form "B" to update based on what vessel I choose in form "A". I know this is an easy one. :)
2
2760
by: angi35 | last post by:
I hope this is an easy question for someone out there. In Access 2000…I have a MainForm with a tab control (MAIN TABS) with 7 tabs. Within each tab is a SubForm. Within each SubForm is a tab control (TabCtl0) with 2-6 tabs. Within each TabCtl0, each tab contains a SubSubForm. Each record in the MainForm has an ID Number; the SubForms are...
1
1758
by: Crombam | last post by:
Hi to all, After searching the net for a couple of hours I just have to ask the question. How can I close a report with a subform (Pivot Chart) when this Pivot Chart is having no data? Explenation: I have a report, which displays a Pivot Chart (Subform). When clicking a command button for displaying this report a form pop-up wil appear,...
3
1492
by: gblack301 | last post by:
Hi All, I have been racking my brain for sometime in trying to resolve this and now I am just wiped out. MS-Access 2003 I have a main form that contains several selection options (combo boxes). This main form is opened with an argument from another form and this main form is bound to a table. The main form has a subform that is bound...
7
2139
by: JohnHo | last post by:
I have been working with Access for a little while but have never used mainforms/subforms before. Here is my problem/scenario: I have a main form (frmMain) with a few other forms for data data entry (frmOne, frmTwo, ...). I have the same table (tblCallLog) as the record source for each of these forms. I have used the MainForm and SubForm...
8
6596
by: Erik Pen | last post by:
My main form has several subforms which display the results of queries. I want to display a message in a subform when it's query is empty indicating that there are no records meeting the form's criteria. wondering how this can be done. Thanks Erik
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5208
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.