Macro does not work in a subform (1 Viewer)

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
Hello,
I have a sub form that contains two fields of FabricNum(ComboBox) and RollNum(ComboBox). The RollNum is restricted to the FabricNum so whenever I choose a FabricNum, list of RollNum changes respectively.
In order to do that, I created a query that contains the FabricNum and RollNum. The FabricNum in the query is restricted to the chosen FabricNum in the subform. I also have an embedded macro on FabricNum which opens the query, close the query and requery based on RollNumber. All what I have explained work perfect once it gets done in a sub form. When I try to do the same thing in a Main form, it does give me an error.
After researches I realized that I have to change the path in a query and I changed it as following: [Forms]![FabricUsageDetail1].[FabricUsageDetail2].[Form].[FabricNum]. Unfortunately, I still get an error of 2950 which says the command or action ‘Requery’ is not available now.
I would be thankful if anyone could help me solve this problem.
 

JHB

Have been here a while
Local time
Today, 01:21
Joined
Jun 17, 2012
Messages
7,732
It looks for me not correct.
Code:
[SIZE=3][FONT=Calibri][Forms]![B][COLOR=Red][FabricUsageDetail1].[FabricUsageDetail2][/COLOR][/B].[Form].[FabricNum].[/FONT][/SIZE]
What is [FabricUsageDetail1] and [FabricUsageDetail2]?

 

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
Thanks for the response.
The "FabricUsageDetail1" is the main form and "FabricUsageDetail2" is the sub form.
I am not sure what the problem is but I think I need to make a link between my Main and Sub form which I have not done it yet and I do not know how to do it. I guess the macro does not define the main form because there is no path indicated in the main form,that is why it can not be run from the main form.
 

JHB

Have been here a while
Local time
Today, 01:21
Joined
Jun 17, 2012
Messages
7,732
Post your database with some sample data, (zip it then you have not post 10 post yet).
 

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
Thanks again.
Unfortunately I can not do that. System designed in a way that only staff who are in the office are permitted to open databases not anywhere else due to data confidentiality. Even if I send it, you would not be able to open the file.
I am pretty sure I can fix it if you could let me know how to do it.
 

JHB

Have been here a while
Local time
Today, 01:21
Joined
Jun 17, 2012
Messages
7,732
Ok - I asked for sample data in the table and only the forms that made problem, but never mind about that.
I'll try on another way.
Open the form in "Form view", open a new query with the table in, select the field where [FabricNum] referred to place the cursor in the criteria click on the
the the below box open. Choose Forms ->Loaded Forms-Maim form and sub form. Chose relevant text control/combo box
and "Value".
Then the references to the subform should be correct, then copy the line.
 

Attachments

  • Builder.jpg
    Builder.jpg
    1.3 KB · Views: 426
  • Exp.jpg
    Exp.jpg
    83.9 KB · Views: 452

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
Sorry for the late response, it is only because of time difference.
Thank you So much for your time but unfortunately I could not get it work. I created a dummy database and I put relative tables, queries and forms into it as you wanted. I really appreciate your help.
 

Attachments

  • Milad_Database.zip
    59.4 KB · Views: 74

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
There are two Inventory tables which stores the FabricNum and PieceNum=RollNum. I created a query that gets FabricNum and PieceNum from Inventory table1&2. I restricted FabricNum (combobox) and PieceNum (Combobox) in FabricUsageTable1&2, in the query's values. In order to that, In my form which is created based on FabricUsage1&2 table, I tried to link the combo box for FabricNum to The FabricNum in my query. I also linked the PieceNum (Combobox) in my form to PieceNum in query. Finally I had this plan to make the form gets updated automatically. In other words, when I choose my Fabric Num the piecenum which is restricted to FabricNum shows up.
 

JHB

Have been here a while
Local time
Today, 01:21
Joined
Jun 17, 2012
Messages
7,732
Is this what you wanted?
 

Attachments

  • Milad_Database.accdb
    560 KB · Views: 105

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
I really don't know how to thank you. This is exactly what I wanted. I really appreciate your help.
 

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
Hello, I am trying to do the same thing for another form but somehow it does not work. can you help me out please.

Thanks in advance
 

JHB

Have been here a while
Local time
Today, 01:21
Joined
Jun 17, 2012
Messages
7,732
Then tell my which form + post the database.
 

Milad

Registered User.
Local time
Yesterday, 20:21
Joined
Jul 8, 2013
Messages
27
I figured it out. I referenced my combo box to a wrong table.
Thanks for your quick response BTW. :)
 

Users who are viewing this thread

Top Bottom