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

Get Correct Value

Form1 is bound to a table with two columns: Week_Number, Week_Date. Work_Number column has numbers 1 though 52. Week_Date has the date of each Saturday in the year. When a user clicks on a row, I want that "Click" to open Form2 and pass the Week_Number value to Form_2.

Form_2 has three columns: Week_Number, Home_Team_ID, and Away_Team_ID. When it opens, I want the "cursor" to be on the first row that corresponds to the passed value. Also, I want to display only those rows which match this value.

How do I make this happen?

Lastly, would this be harder or easier using a sub-form?
Feb 12 '13 #1
15 1294
Seth Schrock
2,965 Expert 2GB
If there are multiple records in Form_2 that have the same Week_Number, then a subform would be the way to go. If there is only one record in Form_2 for each record in Form_1, then you could put them all on the same form using a query to combine the data or just combine all the fields into one table. But if you want them on separate forms, then something like
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Form_2"
  2. DoCmd.SearchForRecord "Week_Number = " & Me.Week_Number
I prefer this method as it doesn't set the form's filter.
Feb 12 '13 #2
ADezii
8,834 Expert 8TB
  1. You can pass the Value of the [Week_Number] Field in Form1 to Form2 via the OpenArgs Property of Form1, namely:
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acWindowNormal, Me![Week_Number]
  2. To then access this Value and act accordingly in Form2:
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print Me.OpenArgs
Feb 12 '13 #3
NeoPa
32,556 Expert Mod 16PB
I would use a main form displayed in Continuous View and link to a subform in Single View using the Week_Number from both forms.
Feb 12 '13 #4
I created two forms. In the first form, I added
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.    DoCmd.OpenForm "All_Matches_Frm", , , , , , Me.WeekNmbr
  3. End Sub
to the "On Click" property. However, it does NOT open the second Form. There is no error produced. It just seems to ignore the click. Anyone got any ideas?
Feb 12 '13 #5
NeoPa
32,556 Expert Mod 16PB
Have you set the form up to use this code? Is the form's Click event set to "[Event Procedure]"?
Feb 13 '13 #6
@NeoPa
Yes. And procedure is set to:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.    DoCmd.OpenForm "All_Matches_Frm", , , "WeekNmbr = Me.WeekNmbr", , , "Me.WeekNmbr"
  3. End Sub
Feb 13 '13 #7
Seth Schrock
2,965 Expert 2GB
Please use the [CODE/] button when posting code. It makes it a lot easier to read.

Not sure why your form isn't opening, especially if there are no errors. Unless it is opening in a hidden view somehow. Try putting the word Stop right before the DoCmd.OpenForm... just so that you know what you are clicking is triggering the form's OnClick event. If the Stop doesn't get highlighted in yellow (by default it is yellow anyway) with the code in break mode, then the event isn't triggering.

Also, your Where Condition is wrong. You need to make it be
Expand|Select|Wrap|Line Numbers
  1. "WeekNmbr = " & Me.WeekNmbr
You also don't need to use both the Where Condition and the Open Args. Using the Where condition opens the form with a filter applied. Using the Open Args lets you do a Me.FindNext in your second form's OnLoad event that will just find the record you want instead of placing a filter on the form. One is not better than the other just because, but each has its own purpose and you just need to decide which you want.
Feb 13 '13 #8
Rabbit
12,516 Expert Mod 8TB
You're using the form click event? I don't think that triggers just by clicking anywhere on a form. It has to be record selector or a blank area on the form. If you're actually clicking on a control, you will need to use that control's click event.
Feb 13 '13 #9
I am clicking on one of the rows displayed in the form.

Seth, Thx for the reply. At this point, I'd be happy to just be able to get the second form to open by clicking in the first form.
Feb 13 '13 #10
Seth Schrock
2,965 Expert 2GB
Like Rabbit, I'm not sure exactly where you have to click to get the form's OnClick event to run. So, just for now, try adding a button to your form and we can use its OnClick event so that we know that the event is triggering. Just put the code that you have in the button's OnClick event. Then click the button and tell us what happens. If you get an error message, we need the number and the exact wording of it.

Also, read the following link, paying particular attention to the first section (A. For VBA code specifically) and make sure that you have Option Explicit set and that you can compile your code without errors: Before Posting (VBA or SQL) Code. This could help us find some of the problems.
Feb 13 '13 #11
My Visual Basic for Access does not seem to have a compile option. but I created the button as you suggested and it DID IN FACT open the second form. And it used the WeekNmbr value to select only those rows that matched. Thank you all so much for your help. Should I leave well enough alone, or should I continue my efforts to make clicking on a row open the second form?

Have any of you ever made a form that displayed the rows from a table and when you clicked on any particular row, it opened another form and passed the row data from the first form?
Feb 13 '13 #12
Seth Schrock
2,965 Expert 2GB
That is really up to you. You just need to figure out what tiggers the form's OnClick event. There must be a certain part of the form that triggers it, but I'm not sure which part. Is your form's Record Selectors property set to Yes or No? If yes, then you should see a gray bar on the left side of the form if you are in Form view and just left of the first field if you are in datasheet view. Either way, try clicking it and see if the event triggers.
Feb 13 '13 #13
zmbd
5,501 Expert Mod 4TB
JackMack: Did you look for the compiler under the [Debug] tools in the ribbon?
Feb 13 '13 #14
No. I didn't. But after reading your note, I tried that and sure enuf, there it is. Thx for the tip.
Feb 13 '13 #15
Rabbit
12,516 Expert Mod 8TB
The form click event only triggers when clicking on the record selector or a blank area on the form. When you say you're clicking on a "row", you are probably clicking on a control. That triggers the control's click event. It does not trigger the form's click event.
Feb 13 '13 #16

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

Similar topics

8
by: Huibuh | last post by:
I start hating RETURN!!! list<happy> //#include <list>// is searched via iterator (ptr) so long until the argument "number" of the class "happy" is equal now. The function "findhappy" works...
6
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the...
7
by: Dew | last post by:
Hi All The problem is related to strtod()/atof()'s well known behaviour. strtod()/atof() add some extra digits at the end of precision while converting from string to double. Becasue...
0
by: thisis | last post by:
Hi All, I'm getting an error on my ASP page: Microsoft VBScript runtime error '800a000d' Type mismatch: 'StoreFileIntoField' I assume - 99.5% - the error is generated because of worng...
0
by: thisis | last post by:
Hi All, I'm getting an error on my ASP page: Microsoft VBScript runtime error '800a000d' Type mismatch: 'StoreFileIntoField' I assume - 99.5% - the error is generated because of worng...
23
by: Anders Borum | last post by:
Hi! I am implementing a threaded producer / consumer pattern just for fun. I am using an internal counter to keep track of the produced / consumed items and am logging that information. I am...
1
by: kang jia | last post by:
hi currently i am editing signup page, when user enter deupicated NRIC and click signup, they will go to do_signuppage and read the error message and then after 5 seconds, they will be redirected...
2
by: vsc33 | last post by:
Hello, I have a vb.net application that runs on a server. There are five client PC's that are connected to the server and all the data is saved on the server from my vb.net application. To add...
9
by: Blerta | last post by:
Hello, If anyone can help me on this issue? I have a table, field1 has value for 4 years and field two has value only for the last year. I want to calculate Field3=field2/field1 the view is like...
7
by: Ryan Le Piane | last post by:
Hi everyone, I am trying to program a Form Pay Estimator and it calculates the gross pay, taxes owed, and net pay for an individual employee. For some reason my CalculateTaxes method in my Pay()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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
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
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,...

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.