Showing posts with label Data retreival. Show all posts
Showing posts with label Data retreival. Show all posts

Friday, January 13, 2012

Getting Data From Another Form in MS Access

Sometimes in order to run the VBA code I need data from a form other than the one that contains the code. For example, I have a form that shows all the data for an folder in a collection, frmFolderData. In order to pull the data to populate that form I need to know the folder’s index number. If frmFolderData is being opened from the list of folders in frmSeriesFolderList it is pretty simple:

     lngFolderID = Forms!frmSeriesFolderList.lstFolder.Column(0)

Where lngFolderID is a long variable for the folder index number, which is in the first column of the list box.

However if that is the code I use and then try to open frmFolderData from frmEADFolders I will get an error because frmSeriesFolderList is not open. I need to test for whether or not the form I want is open, or in this case, which of the two forms I could use is open. To do that I use the IsLoaded property.

Here is the code used in frmFolderData to decide whether to pull the needed data from frmSeriesFolderData or frmEADFolders:

     If CurrentProject.AllForms("frmSeriesFolderList").IsLoaded Then
          lngFolderID = Forms!frmSeriesFolderList.lstFolder.Column(0)
     ElseIf CurrentProject.AllForms("frmEADFolders").IsLoaded Then
          lngFolderID = Forms!frmEADFolders.lstFolders.Column(0)
     End If