473,569 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"On Open" Event; applying a query to open a form

kcdoell
230 New Member
Hello:

I have a form that I want to open using a filter that I have created. I have done this usually by pointing the record source of the form to the query/filter that I created. In this new project, I want to open the form using the "On Open" event, via the properties of the form, and leave my record source pointing to the original table that was used to set it up.

My problem is that I am not too sure what the vba coding would be. This particular form has a subform that displays data. I later want to place a command button on the form that will change the sort of the displayed dataset if the user indicates what sort they want the table/dataset to be in.

Does anybody have any ideas they could give me?

Thanks,

Keith.
Feb 6 '08 #1
7 2679
MMcCarthy
14,534 Recognized Expert Moderator MVP
Not sure I fully understand what you are looking for but ...

Me.filter = "[Fieldname]=" & someValue
Me.filterOn
Feb 6 '08 #2
kcdoell
230 New Member
Thanks for the reply!

I tried to apply the Me.filter idea by putting the following code in the "on Open" property of the form:

Private Sub Form_Load()
Me.Filter = "QryForecastfor m"
End Sub

Can I reference a query (like I am doing) because it currently does not work? I basically just want the form to initially load up using a filter that I created in Access called "QryForecastfor m".

Any ideas?

Thanks

Keith.
Feb 7 '08 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Thanks for the reply!

I tried to apply the Me.filter idea by putting the following code in the "on Open" property of the form:

Private Sub Form_Load()
Me.Filter = "QryForecastfor m"
End Sub

Can I reference a query (like I am doing) because it currently does not work? I basically just want the form to initially load up using a filter that I created in Access called "QryForecastfor m".

Any ideas?

Thanks

Keith.
Thats not a filter its a query so you would reset the record source of the form.

Private Sub Form_Load()
Me.RecordSource = "QryForecastfor m"
End Sub
Feb 7 '08 #4
kcdoell
230 New Member
Thanks, that worked but I discovered that it only worked if I put the code in both the Main form and the Sub form (when I created the form I have a subform embedded in it). Not too sure why....

I have another quick question that is related; on the form I want to change the way the subform is displaying the info (the sort order). That is to say that the subform is in a datasheet view and I want to give the user the ability to see the same information in different sort orders (By Name, Location, Product, etc).

I placed a combo box on my form called "cobSort" and in there is a drop down list to choose from (Name, Location, Product, etc). Then I put a command button called "cmdReSort_ Tbl" and on the onclick property I put the following code:

Private Sub cmdReSort_Tbl_C lick()
'When user makes a selection on the Sort Table dropdown menu the table will requery
' via that sort parameter

If cobSort = "Name" Then
Me.RecordSource = "UWQryFormS ort"
End If

End Sub

_______________


You can see that I have another query called "UWQryFormS ort" that is exactly the same as my first one except I put this one in ascending order under the field called "Name". When I clicked on the button it does not change the sort order of the table though I did confirm that my query does.

What am I doing wrong? I thought that the Me.RecordSource method would work in this new event.

Thanks again,

Keith.
Feb 7 '08 #5
jaxjagfan
254 Recognized Expert Contributor
Thanks, that worked but I discovered that it only worked if I put the code in both the Main form and the Sub form (when I created the form I have a subform embedded in it). Not too sure why....

I have another quick question that is related; on the form I want to change the way the subform is displaying the info (the sort order). That is to say that the subform is in a datasheet view and I want to give the user the ability to see the same information in different sort orders (By Name, Location, Product, etc).

I placed a combo box on my form called "cobSort" and in there is a drop down list to choose from (Name, Location, Product, etc). Then I put a command button called "cmdReSort_ Tbl" and on the onclick property I put the following code:

Private Sub cmdReSort_Tbl_C lick()
'When user makes a selection on the Sort Table dropdown menu the table will requery
' via that sort parameter

If cobSort = "Name" Then
Me.RecordSource = "UWQryFormS ort"
End If

End Sub

_______________


You can see that I have another query called "UWQryFormS ort" that is exactly the same as my first one except I put this one in ascending order under the field called "Name". When I clicked on the button it does not change the sort order of the table though I did confirm that my query does.

What am I doing wrong? I thought that the Me.RecordSource method would work in this new event.

Thanks again,

Keith.
If using the combo to define the column to sort - should be something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReSort_Tbl_Click()
  2. Dim strCtl
  3. strCtl = Me.cobSort
  4. Docmd.GoToControl strCtl
  5. DoCmd.RunCommand acCmdSortAscending
  6. End Sub
  7.  
Feb 7 '08 #6
kcdoell
230 New Member
I receive an error message (runtime 2109) indicating that "There is no field name 'Name' in the current record"

Could that be happening because the code is tied to the form and not the subform that is displaying the table?

Keith.
Feb 7 '08 #7
kcdoell
230 New Member
You guys were great.... I played around with it and got it to work. All I needed to do was change my subform's default view from a datasheet to a continuous form and then I embedded my cobSort in the header of the subform. I also got rid of the command button and put the code in the after update event of my cobSort control to make it look cleaner and to save a click.

Thanks a lot!

:-)

Keith.
Feb 7 '08 #8

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

Similar topics

6
1998
by: John Baker | last post by:
Hi: Does "On Open" code execute before or after related data is loaded? I want to test before the form appears on the screen to see if there is any data in the queryresult, and if there is not then I want to close the form unseen by the end user. Regards John baker
7
2553
by: Aaron G via AccessMonster.com | last post by:
Wanted to share a solution to something which I didn't find on the net: EVERY form in my Microsoft Access 2002 database gave an error any time any code was to be called: form OnOpen, button OnClick, etc. Error was: <b>The expression On Open you entered as the event property setting produced the following error: Expecteed: end of...
2
4902
by: Serge Klokov | last post by:
Hi! 1. Please, help with example "paint on form by mouse" 2. Below is my example, but it clear the line after each Refresh()... how to fix? 3. How to draw the line in Mouse_Move event? private Boolean isCanPaint = false; private MouseEventArgs MouseEvent1;
15
2904
by: Billy | last post by:
Anyone know if this a bug in VB.NET 2002 and how to overcame that situation? I have a MDI form from where I call MDI child form like that: Dim frm As New frmChild() frm.MdiParent = Me frm.Show() On that child form I have some textboxes. When form show up Leave event
6
3608
by: Grumpy Aero Guy | last post by:
I would like to add functionality to a form that contains a check box with which the end user can check it so that this particular form won't appear again. I. e., a "Don't show this form again" box. What approach is generally recommended to implement such functionality. A general approach would be appreciated...I can probably get there...
1
1602
by: S. van Beek | last post by:
Dear reader, First of all a happy new year. In Report event there is the "On No Date" event but in a Form this event is not available.
2
1941
by: jerry.ranch | last post by:
I'm starting to learn about the tab control. How would I write an on open event procedure in VBA, that upon opening of the form, a specific tab opens (say tab 1)? Thanks Jerry
3
2751
by: RR | last post by:
I have a button on a form (form A) that opens another form. The form that opens (form B) has a listbox that is populated with a call to a function in the "on current" event. When form B with the listbox has a query listed as the data source, it works fine. In this case, the button on form A sets the record source for form B to one of...
3
1890
by: Joanne | last post by:
I have searched through previous threads regarding this error. I went back through all my code to make sure I closed and set to nothing all open db's and rs's. However, I still have one computer getting this error. This problem does not occur with any other users - some of whom use the database continuously. The user logs in, then goes...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.