[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

Open Forms with no data showing

I have a main form with a tab control that contains several inserted subforms.  When I load/open the main form, data appears on the screen.  The main data for the subforms is populated by the main form combo box field which is the primary key for the main form.  

How to I keep data from appearing on the main form and subforms when the form is first opened, without wiping the data out of the table?
0
gdunn59
Asked:
gdunn59
1 Solution
 
JohnK813Commented:
Is it safe to assume you're using Microsoft Access?  If so, in your main forms and each of your subforms, go to your Form Properties -> Data tab -> Record Source, and clear whatever is there.

In your VBA code, whenever you want data to first appear in the main form, enter the line:

Me.RecordSource = (Main form recordsource)

For example:

Me.RecordSource = "tblMain"
or
Me.RecordSource = "SELECT * FROM tblMain"

To update your subforms:
In your main form:

Private Sub Combo1_AfterUpdate()
  Me.SubformName.Requery
End Sub

In the Subform:

Private Sub Form_Current()
  Dim strValue as String
  strValue = Forms!MainForm.Controls!Combo1.Value
  Me.RecordSource = "SELECT * FROM tblMain WHERE SomeField = " & strValue
End Sub

I'm sure you'll have questions on this, so feel free to ask them.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now