Taras
asked on
MS Access filter Form from one database in another database
I have two databased files.
CurrentDb and HistoryDB in MS Access 2003.
From a form in HistoryDB on command button click event I need next:
I want to open two bound forms in CurrentDB with particular record in
then I want to close HistoryDB and have CurrentDB form frmMainEdit stay opened and frmMainOutstand should be hidden.
I started with some code as bellow but can not figure out how to Filter those forms.
************************** ********** ********
Private Sub CmdOpen_Form_In_CurrentDat abase_Clic k()
Dim strDB As String
strDB = "D:\Databases\CurrentdB.md b"
Dim appAccess As Access.Application
Set appAccess = New Access.Application
Dim strFilter1 as string
strFilter1 = "Some text xxxxxx"
appAccess.OpenCurrentDatab ase strDB
appAccess.Visible = True
appAccess.UserControl = True
stDocName = "frmMainOutStand"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainOutstand!sfrm MainOutSta ndCurr.For m.Filter = strFilter1
Forms!frmMainOutstand!sfrm MainOutSta ndCurr.For m.FilterOn = True
Forms!frmMainOutstand!sfrm MainOutSta ndHis.Form .Filter = strFilter1
Forms!frmMainOutstand!sfrm MainOutSta ndHis.Form .FilterOn = True
stDocName = "frmMainEdit"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainEdit.Form.Fil ter = strFilter1
Forms!frmMainEdit.Form.Fil terOn = True
DoCmd.Quit
End Sub
CurrentDb and HistoryDB in MS Access 2003.
From a form in HistoryDB on command button click event I need next:
I want to open two bound forms in CurrentDB with particular record in
then I want to close HistoryDB and have CurrentDB form frmMainEdit stay opened and frmMainOutstand should be hidden.
I started with some code as bellow but can not figure out how to Filter those forms.
**************************
Private Sub CmdOpen_Form_In_CurrentDat
Dim strDB As String
strDB = "D:\Databases\CurrentdB.md
Dim appAccess As Access.Application
Set appAccess = New Access.Application
Dim strFilter1 as string
strFilter1 = "Some text xxxxxx"
appAccess.OpenCurrentDatab
appAccess.Visible = True
appAccess.UserControl = True
stDocName = "frmMainOutStand"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
stDocName = "frmMainEdit"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainEdit.Form.Fil
Forms!frmMainEdit.Form.Fil
DoCmd.Quit
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
User wants to have some setup of current and archive- history database of services that hi perform for customers.
In History database he would like to store data from previous years and he want to use current database just for current year records.
From time to time he wants to go to HistoryDB find old record bring it I current database make some changes and make it new record.
So they ask me to create this scenario make copy of current database and name it HistoryDB , then empty some tables in HistoryDB. Then create separate form in CurrentDB with command button and one field (text box) for entering a year of export. Then by click on button export all records from CurrentDb for particular year in HistoryDB.
From time to time they go back to HistoryDB and look for particular record(service)
In History database they need all features (search,reports,… as current database have)and extra option they want to pick up particular record from HistoryDB and bring it in CurrentDB and making it new record(new ID and so on)
Scenario is unusual and open for complication, but that is what I have to deal with.
I was thinking about referencing CurrentDb from HistoryDB. Then create in Currentdb in a module public function: Public Function OpenFormInCurrentWithPasse dParameter sFromHisto ry(my filter field values).
So I can call from HistoryDB that Function in CurrentDB and fire those form open procedure with passed filters.
Or I can create in this function SQL select statements that pull records from CurrentDB and make forms record source to these SQL statements and open them.
What do you think about this option referencing CurrentDB in HistoryDB?
In History database he would like to store data from previous years and he want to use current database just for current year records.
From time to time he wants to go to HistoryDB find old record bring it I current database make some changes and make it new record.
So they ask me to create this scenario make copy of current database and name it HistoryDB , then empty some tables in HistoryDB. Then create separate form in CurrentDB with command button and one field (text box) for entering a year of export. Then by click on button export all records from CurrentDb for particular year in HistoryDB.
From time to time they go back to HistoryDB and look for particular record(service)
In History database they need all features (search,reports,… as current database have)and extra option they want to pick up particular record from HistoryDB and bring it in CurrentDB and making it new record(new ID and so on)
Scenario is unusual and open for complication, but that is what I have to deal with.
I was thinking about referencing CurrentDb from HistoryDB. Then create in Currentdb in a module public function: Public Function OpenFormInCurrentWithPasse
So I can call from HistoryDB that Function in CurrentDB and fire those form open procedure with passed filters.
Or I can create in this function SQL select statements that pull records from CurrentDB and make forms record source to these SQL statements and open them.
What do you think about this option referencing CurrentDB in HistoryDB?
ASKER
Is referencing CurrentDB in HistoryDB that what Pat refered when she said link HistoryDB to CurrentDB?
Creating historical data, and linking it back to your current "live" data, is fairly commonplace. Linking the historical tables to the "live" database would be the simplest and easiest method, by far. If you have Form in the history db that need to be used, move them to the "live" db and call them from there, and use the linked tables in those forms when needed.
Creating historical data, and linking it back to your current "live" data, is fairly commonplace. Linking the historical tables to the "live" database would be the simplest and easiest method, by far. If you have Form in the history db that need to be used, move them to the "live" db and call them from there, and use the linked tables in those forms when needed.
ASKER
Thank You a lot
ASKER
Private Sub CmdOpen_Form_In_CurrentDat
Dim strDB As String
strDB = "D:\Databases\CurrentdB.md
Dim appAccess As Access.Application
Set appAccess = New Access.Application
Dim strFilter1 as string
Dim lngServiceID As Long
Dim strCAllBackID As String
Dim strTerr As String
Dim strContrID As String
lngServiceID = Me.ServiceID
If Nz(Me.ServiceID, 0) = 0 Or Me.ServiceID = "" Then
MsgBox "Please Check Service ID number"
Exit Sub
End If
strCAllBackID = Me.CallBackID
If Nz(Me.CallBackID, "") = "" Or Me.CallBackID = "" Then
MsgBox "Please Check Callback ID number"
Exit Sub
End If
strTerr = Me.TerritoryID
If Nz(Me.TerritoryID, "") = "" Or Me.TerritoryID = "" Then
MsgBox "Please check Territory ID number"
Exit Sub
End If
strContrID = Me.ContractorID
If Nz(Me.ContractorID, "") = "" Or Me.ContractorID = "" Then
MsgBox "Please check Contractor ID "
Exit Sub
End If
StrFilter1 = " [TerritoryID]='" & strTerr & "' And [CallBackID] = '" & strCAllBackID & " ' And [ServiceID] = " & lngServiceID & " And [ContractorID] ='" & strContrID & "' "
appAccess.OpenCurrentDatab
appAccess.Visible = True
appAccess.UserControl = True
stDocName = "frmMainOutStand"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
Forms!frmMainOutstand!sfrm
stDocName = "frmMainEdit"
appAccess.DoCmd.OpenForm stDocName
Forms!frmMainEdit.Form.Fil
Forms!frmMainEdit.Form.Fil
DoCmd.Quit
End Sub