![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have one form "frmInvoiceCash" which can be called from lots of different places in my application. I currently use the following code to pick the correct datatsource : - Private Sub Form_Open(Cancel As Integer) If IsLoaded("frmunpaid") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]![frmunpaid]! [invoiceid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmuninvoiced") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]![frmuninvoiced]! [invoiceidun]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmallocate") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]![frmallocate]! [txtinvoiceid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmproductmovement") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]! [frmproductmovement]![invoiceid]));" Forms!frminvoicecash.DataEntry = False Forms!frminvoicecash!InvoiceNote = Forms!frminvoicecash! InvoiceNote & " " ElseIf IsLoaded("frmstatement") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]![frmstatement]! [invoiceid]));" Forms!frminvoicecash.DataEntry = False Forms!frminvoicecash!sfmCashInvoicePayment.Visible = False Forms!frminvoicecash!txtPaid.Visible = False Forms!frminvoicecash!lblPaid.Visible = False Forms!frminvoicecash!lblDue.Visible = False Forms!frminvoicecash!txtDue.Visible = False ElseIf IsLoaded("frminvsearch") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]![frminvsearch]! [txtinvid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmAccountCustomerHistory") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE " & _ "(((tblInvoice.InvoiceID)=[Forms]! [frmaccountcustomerhistory]![txtinvoiceid]));" Forms!frminvoicecash.DataEntry = False Else Forms!frminvoicecash.RecordSource = "tblinvoice" Forms!frminvoicecash.DataEntry = True End If Me.Requery End Sub There are some issues with this e.g. if you have two of the forms open then it uses the datasource for the first one in the list. My question is whether opr not there is an easier way of doing this. I will be adding at least another three forms to the app which can be used to open frmInvoiceCash so want to nail this before I add them. Ultimately only one form should be able to be openend at any one time to prevent the use of an incorrect datasource |
#3
| |||
| |||
|
|
I have one form "frmInvoiceCash" which can be called from lots of different places in my application. I currently use the following code to pick the correct datatsource : - Private Sub Form_Open(Cancel As Integer) If IsLoaded("frmunpaid") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]![frmunpaid]! [invoiceid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmuninvoiced") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]![frmuninvoiced]! [invoiceidun]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmallocate") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]![frmallocate]! [txtinvoiceid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmproductmovement") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]! [frmproductmovement]![invoiceid]));" Forms!frminvoicecash.DataEntry = False Forms!frminvoicecash!InvoiceNote = Forms!frminvoicecash! InvoiceNote& "" ElseIf IsLoaded("frmstatement") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]![frmstatement]! [invoiceid]));" Forms!frminvoicecash.DataEntry = False Forms!frminvoicecash!sfmCashInvoicePayment.Visible = False Forms!frminvoicecash!txtPaid.Visible = False Forms!frminvoicecash!lblPaid.Visible = False Forms!frminvoicecash!lblDue.Visible = False Forms!frminvoicecash!txtDue.Visible = False ElseIf IsLoaded("frminvsearch") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]![frminvsearch]! [txtinvid]));" Forms!frminvoicecash.DataEntry = False ElseIf IsLoaded("frmAccountCustomerHistory") Then Forms!frminvoicecash.RecordSource = "SELECT tblInvoice.*FROM tblInvoice WHERE "& _ "(((tblInvoice.InvoiceID)=[Forms]! [frmaccountcustomerhistory]![txtinvoiceid]));" Forms!frminvoicecash.DataEntry = False Else Forms!frminvoicecash.RecordSource = "tblinvoice" Forms!frminvoicecash.DataEntry = True End If Me.Requery End Sub There are some issues with this e.g. if you have two of the forms open then it uses the datasource for the first one in the list. My question is whether opr not there is an easier way of doing this. I will be adding at least another three forms to the app which can be used to open frmInvoiceCash so want to nail this before I add them. Ultimately only one form should be able to be openend at any one time to prevent the use of an incorrect datasource |
#4
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |