Results 1 to 9 of 9

Thread: SourceObject

  1. #1
    Join Date
    Jan 2004
    Posts
    4

    Unanswered: SourceObject

    I have a a database with an unbound subform on the main form. A text box with an on click event procedure opens the form I want in the sub form however I cannot get it to open the form displaying a new record, it displays the 1st record.

    I also have another text box with a combo of the primary keys from a table. On the after update procedure I want the unbound sourceobject to display a form with the specific record selected in the combobox

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: SourceObject

    For the first problem. put this code in the subform that you want to open.

    On the fomr's On_open event

    docmd.GoToRecord,,acNewRec

    For the sencond question use
    Docmd.FindRecord.....


    Originally posted by wattsa
    I have a a database with an unbound subform on the main form. A text box with an on click event procedure opens the form I want in the sub form however I cannot get it to open the form displaying a new record, it displays the 1st record.

    I also have another text box with a combo of the primary keys from a table. On the after update procedure I want the unbound sourceobject to display a form with the specific record selected in the combobox

  3. #3
    Join Date
    Jan 2004
    Posts
    4

    Re: SourceObject

    Originally posted by khan
    For the first problem. put this code in the subform that you want to open.

    On the fomr's On_open event

    docmd.GoToRecord,,acNewRec

    For the sencond question use
    Docmd.FindRecord.....
    Khan,

    OK for the 2nd question where do I put this code? Do i put it in th open event on the subform and use an IF command to see if the main form combo is populated else do the new record, or somewhere else?

  4. #4
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: SourceObject

    Please can you explain your second question ina bit more detail.


    Originally posted by wattsa
    Khan,

    OK for the 2nd question where do I put this code? Do i put it in th open event on the subform and use an IF command to see if the main form combo is populated else do the new record, or somewhere else?

  5. #5
    Join Date
    Jan 2004
    Posts
    4

    Re: SourceObject

    Originally posted by khan
    Please can you explain your second question ina bit more detail.
    Khan,

    The main form I have is called fdlg_invoices, with two text boxes. The 1st text box is 'Enter new record' and when you click on this I want a new record to appear in the unbound source object subform. For the sub form to appear I have the following code on the on_click event procedure for the 'Enter new Record' text box: -

    Me![Sub].Visible = True
    Me![Sub].SourceObject = "Frm_Invoices"
    Me.Sub.SetFocus

    This makes the form appear but not on a new record so I put your code in on the on_open event procedure for Frm_Invoices: -

    DoCmd.GoToRecord , , acNewRec

    This works fine, however the 2nd combo box 'LoadInvoice' on fdlg_invoices has the following row source:

    SELECT [Tbl_Invoices].[InvoiceNo], [Tbl_Invoices].[SupplierID] FROM Tbl_Invoices ORDER BY [Tbl_Invoices].[InvoiceNo];

    What I want to happen is after update of 'LoadInvoice' is for frm_invoices to appear in the unbound subform on the appropriate InvoiceNo record. However I want to know where to enter the DoCmd.GotoRecord code as I dont want it to clash with the enter new record code

    If a value is located in the combo box I still want to be able to click on the new record text box if required to load a new record

  6. #6
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: SourceObject

    Okay now I got it..Well in such situation you manipulate the subform from within the subform. That is in yoursubform Onopen event check which textbox is active control. You can use the following code.

    me.parent.form.activeControl

    if the active control is the "Enter New record" then
    DoCmd.GoToRecord , , acNewRec

    if the active control is "Load Invoices" then capture the invoice no. like
    strInvoiceNo=me.parent.form.activecontrol.Value
    Docmd.findRecord strInvoiceNo

    Try it and tell me if it work. If not you can email me you db and I'll take a look.


    Originally posted by wattsa
    Khan,

    The main form I have is called fdlg_invoices, with two text boxes. The 1st text box is 'Enter new record' and when you click on this I want a new record to appear in the unbound source object subform. For the sub form to appear I have the following code on the on_click event procedure for the 'Enter new Record' text box: -

    Me![Sub].Visible = True
    Me![Sub].SourceObject = "Frm_Invoices"
    Me.Sub.SetFocus

    This makes the form appear but not on a new record so I put your code in on the on_open event procedure for Frm_Invoices: -

    DoCmd.GoToRecord , , acNewRec

    This works fine, however the 2nd combo box 'LoadInvoice' on fdlg_invoices has the following row source:

    SELECT [Tbl_Invoices].[InvoiceNo], [Tbl_Invoices].[SupplierID] FROM Tbl_Invoices ORDER BY [Tbl_Invoices].[InvoiceNo];

    What I want to happen is after update of 'LoadInvoice' is for frm_invoices to appear in the unbound subform on the appropriate InvoiceNo record. However I want to know where to enter the DoCmd.GotoRecord code as I dont want it to clash with the enter new record code

    If a value is located in the combo box I still want to be able to click on the new record text box if required to load a new record

  7. #7
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    attach your db and I'll look.

  8. #8
    Join Date
    Jan 2004
    Posts
    4

    See attached

    Originally posted by khan
    attach your db and I'll look.
    Attached Files Attached Files

  9. #9
    Join Date
    Oct 2003
    Location
    US
    Posts
    343
    I looked at your app and man!! I don't understand what are trying to accomplish. I think you should have the subform and you main form both based on queries. The queries should be based on tables having one=many joins. Then your main form will act as the header table where you can either create a new invoice or check the old one. The sub form should show the Details of it. Now you can design the sub form any way you want it. If you like you can have tabbed controls or anything.

    Also its not a good idea to use text boxes as click controls. This is not the norms..

    So try to update your app on these lines.Your problem is not difficut. You can also check the NothWind db that ships with MS Access. it has some good examples for invoices and orders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •