473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

If statement and LinkMasterFields

EJaques
Hello,

I have a list box that controls the display of information on a form and its subform.

I am having problems with the code to change Child/Parent links according to what is selected in the list box and a combo box (both on the main form):

I want:
-the subform to display only the records corresponding to a specific work order when a given order is selected in the list box
-the subform to display all records if "All work orders" is selected
-the subform to display all records for a given month when "All work orders and a month is selected

The code is the AfterUpdate event of the Listbox.


Expand|Select|Wrap|Line Numbers
  1. Private Sub SubFormLinkRules()
  2. 'Decides and sets how subform is linked to Main form
  3.  
  4. Dim strChild As String
  5. Dim strMaster As String
  6.  
  7. If Me.Liste21.ListIndex = 0 Then
  8. '0 corresponds to <All work orders> in the listbox
  9.  If Me.cmbMois = "<All months>" Then  ' Me.cmbMonth is field in the Main form
  10.             strMaster = vbNullString
  11.             strChild = vbNullString
  12.       Else
  13.             strMaster = "[cmbMonth]"
  14.             strChild = "[Month]"   'Month is a field on the subform
  15.     End If
  16.  
  17. Else
  18.       strMaster = "[CodeCmd]" 'CodeCmd is a field on the main form and subform
  19.       strChild = "[CodeCmd]"
  20.  
  21. End If
  22.  
  23. Me.frmCmdComm.LinkMasterFields = strMaster 'frmCmdComm is the subform
  24. Me.frmCmdComm.LinkChildFields = strChild 
  25.  
  26. ' After having selected <All work orders> in the list box
  27.  ' and a value in cmbMonth if I try to select
  28.  ' something further down the listbox I get an error.
  29.  ' I think it is because strMaster isn't changing. But why?
  30.  
  31. End Sub
  32.  
If I try setting the Child/Master links one by one (to test if they work) the subform displays the information I want; so this is not the problem.

Thank you in advance for your insight.
Aug 21 '09 #1
3 3223
ChipR
1,287 Expert 1GB
Have you considered just changing the subformControl.Form.FIlter property?
Aug 21 '09 #2
Have you considered just changing the subformControl.Form.FIlter property?
Like by saying?

Me.frmCmdComm.Form.FilterOn = False

It doesn't work. I don't know why. I don't really want to do that either because
the user can choose to filter the subform by list boxes on the subform also.

Are Child/Master links and Filters the essentially the same !?!
Aug 21 '09 #3
ChipR
1,287 Expert 1GB
This MSDN page says that you can only change the LinkMasterFields and LinkChildFields in design view or Form_Open. You can point the LinkMasterFields to a text box with a calculated value, but you can't for the LinkChildFields. This may prevent you from doing what you intend.
I still use the master and child fields for very simple forms, but when it gets more complicated, I either change the recordsource or the filter dynamically to achieve the same results.

I'm not sure what you mean when you say
Me.frmCmdComm.Form.FilterOn = False
doesn't work.

Perhaps the best way if you need to change the .Filter from within the subform is to change the underlying recordset from the main form. Then you don't have to deal with taking the existing filter string and changing it.
Expand|Select|Wrap|Line Numbers
  1. 'called in the main form
  2. Dim strSQL As String
  3. strSQL = "SELECT * FROM myTable"
  4. If ...
  5.   strSQL = strSQL & " WHERE [month] = " & ...
  6. Else ...
  7.   strSQL = strSQL & " WHERE [codecmd] = & ...
  8. End If
  9. frmCmdComm.Form.RecordSource = strSQL
  10.  
Aug 21 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jaLe | last post by:
This problem was discussed before but it doesn't solve my situation I have master table Generalije with PK: ID1 I added subdatasheet table Nalaz with field FK GeneralijeID When I add new...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
7
by: jgoodnight | last post by:
Hello, I've read through many forum posts on this issue today but can't seem to find a solution that fits my particular case. I have three main tables: - tblIssues (PK: IssueID) -...
1
by: Liveson | last post by:
Hie I have an unbound form on which there are 3 controls: option group, combo box and a subform. The value of the combo box depends on the value of the option group and the value of link child...
1
geolemon
by: geolemon | last post by:
I have a form/subform used for inventory management. It is a bound form. The error: I don't understand what this means. How the form is intended to work: When you select a part number in...
17
by: eranil84 | last post by:
I get this "The LinkMasterFields Property setting has produced this error: 'A problem occurred while Microsoft Office Access was communicating with the OLE server or ActiveX Control' " error message...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.