473,408 Members | 1,749 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,408 software developers and data experts.

Command Button filter on different form

78
I have one form called Accounts, on which there is a command button called EnterNewTransactionButton. This opens another form called Transactions. I want to add some code that will take the value of the AccountNameBox on the form Accounts, and filter the Transactions form with this value. I'm having trouble trying out the various filter form code I've read.

Additionally, I'd love to add a fancy feature: once on the Transaction form and filtered, I'd like to start the new record with the account name that is filtered (not a big deal, but a nice touch :).

I attached a sample database below.
Attached Files
File Type: zip FA Temp.zip (64.2 KB, 161 views)
Apr 30 '08 #1
6 2201
rsmccli
52
This will work for the filtering as the forms stand now. I would put it in the Form_Load event of the subform. You may also want to add some code to check if the Accounts form is open, especially if it will be opened from anywhere besides the Accounts form.

Expand|Select|Wrap|Line Numbers
  1. If Len(Forms.Accounts.AccountNameBox) <> 0 Then
  2.   Me.FilterOn = True
  3.   Me.Filter = "Lookup_VendorID.AccountName='" & Forms.Accounts.AccountNameBox & "'"
  4. Else
  5.   Me.FilterOn = False
  6.   Me.Filter = ""
  7. End If
As a side note, is there a reason why the two corresponding comboboxes are not both 2 column lookups? One is a one column "text" combobox and the other is a standard 2 column with a PK lookup. Just wondering. It would probably help to synchronize those if you want the VendorID combo in the subform to autofill with the selection from AccountNameBox.

hth
rsmccli
Apr 30 '08 #2
kpfunf
78
rsmccli,
Thanks for the code, works great.

Which boxes were you referencing?

Also, do you know how to start a new record with the vendor selected?
Apr 30 '08 #3
rsmccli
52
AccountNameBox and VendorID are the two combos.

btw you are definitely going to want to add a check to see if the account form is open because I see you can access your transactions form from your switchboard. Here is one that I have used that was present in an existing database I work with. It is not pretty, but it works.

Expand|Select|Wrap|Line Numbers
  1. Function IsLoaded(MyFormName)
  2. ' Returns True if specified the form is loaded;
  3. ' False if the specified form is not loaded.
  4. On Error Resume Next
  5.     Dim i
  6.  
  7.     IsLoaded = False
  8.     For i = 0 To Forms.Count - 1
  9.       If Forms(i).FormName = MyFormName Then
  10.         IsLoaded = True
  11.         Exit Function       ' Quit function once form has been found.
  12.       End If
  13.     Next
  14.  
  15. End Function
So once that is pasted into a module you could replace the first line of code from earlier with:

Expand|Select|Wrap|Line Numbers
  1. If IsLoaded("Accounts") = True And Len(Forms.Accounts.AccountNameBox) <> 0 Then
If you do sychronize your combos, once you are on your new record I think you could just put:

Expand|Select|Wrap|Line Numbers
  1. Me.VendorID = Forms.Accounts.AccountNameBox
hth
Apr 30 '08 #4
kpfunf
78
rsmccli,

Thanks again. I changed the combos like you suggested.

The last line of code didn't work though. I've never used code to write a record, so not really sure how to. Any other ideas?
Apr 30 '08 #5
rsmccli
52
I just removed the now redundant DoCmd.GoToRecord , , acNewRec from the command button code and put it in the Transactions subform on load event. Works for me. Sorry I didn't realize you already had a function in place to check for forms being open.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. If IsLoaded("Accounts") Then
  4.   If Len(Forms.Accounts.AccountNameBox) <> 0 Then
  5.     Me.Filter = "Lookup_VendorID.VendorID=" & Forms.Accounts.AccountNameBox
  6.     Me.FilterOn = True
  7.     DoCmd.GoToRecord , , acNewRec
  8.     Me.VendorID = Forms.Accounts.AccountNameBox
  9.   Else
  10.     Me.Filter = ""
  11.     Me.FilterOn = False
  12.     DoCmd.GoToRecord , , acNewRec
  13.   End If
  14. End If
  15.  
  16. End Sub
Apr 30 '08 #6
NeoPa
32,556 Expert Mod 16PB
...
The last line of code didn't work though. I've never used code to write a record, so not really sure how to. Any other ideas?
Try :
Expand|Select|Wrap|Line Numbers
  1. Me.VendorID = Forms!Accounts.AccountNameBox
I suspect it was simply a typo as Forms.Accounts... doesn't resolve.
May 1 '08 #7

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

Similar topics

1
by: reneecccwest | last post by:
Hello, I'd like to pass the "levelbtn" value when I click the filter button, but there are also other submit form buttons. I defined as "document.testform.submit();" in the javascript, but I...
0
by: Steve Bishop | last post by:
I have a form with a search text box and a grid that displays the results. Within the grid, I have edit command links set up to response.redirect to another page that puts the DataKey value in the...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
4
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants...
3
by: chris | last post by:
I have a form det-up as a continous form. In the Header of the form I have a command button called "Approve". What I'm looking to do is when the user clicks the command button all of the records...
3
by: angi35 | last post by:
Working in Access 2000... I have a form with records for every employee. I'd like to create two command buttons so a user can filter the form for either 'only current' or 'only former' employees. I...
3
by: WiscCard | last post by:
This seems simple enough, but I am having problems. I have a table of customer information. I have a form with various combo boxes displaying unique customer information (in this case, zone and...
1
by: eHaak | last post by:
A couple years ago, I built a database in MS Access 2003. I built the form using macros in some of the command buttons, and now I’m trying to eliminate the macros and just use visual basic code. ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.