How can I refresh the data on my access Front End? - vba

I built an access Form frontend with a sharepoint list called "teammates" as the back end.
The form is simple, consists of two listboxes that lists all teammates, one box is for absent teammates, the other is for present teammates. I have some buttons and methods that allow to update a teammates status, thus moving them into either the "absent" list box or the "present" box.
I also have a "Refresh" button on the page.
Private Sub btnRefreshForm_Click()
DoCmd.RunCommand acCmdRefreshSharePointList
CurrentDb.TableDefs("teammates").RefreshLink
Me.lsbAbsentTeammates.Requery
Me.lsbPresentTeammates.Requery
Me.Requery
Me.Refresh
End Sub
My issue is this, when I share the FrontEnd with someone else, that person will send some teammates to the absent box, but I cannot see those changes, the Refresh button does not requery the data.
The only way I can see the updated data is if I close the front end and reopen it.
How can I see the updated data without having to close and reopen the application ?

Related

Endless form not showing after filter applied previously

I am using unbound endless forms to display data from my database.
The data source is set to queries which provide data to show on the form.
All tinkering with the data itself on the form is blocked (entry, adding, deleting, etc.).
The data on the form can, however, be filtered through Access' standard ways (right clicking on the data and selecting the options or through the navigation buttons down the bottom of the form).
I am using another unbound form as a menu. Buttons on the form let the user open the data display forms. The buttons are connected to the forms through an on- click event that triggers a DoCmd.OpenForm ("frmOutput") line of code to display the form.
Recently I've had users report, that opening the endless data display forms from the menu, filtering data on the form and then closing the form without taking the filter out has resulted in the form not being able to be opened again from the menu (clicking the respective button results in no action whatsoever). The bug seems to even save to the application somehow and moving the (frontend) file to another machine still shows the same error of not showing the form.
It seems that the bug appears more often when people use multiple screens, and use the application on their second screen (as per their Windows settings).
Does anybody know what causes the bug or how it can be prevented?
Any pointer in the right direction is much appreciated since I am at a loss where to even start looking for the culprit!
Hard to tell but it sounds like their filter is being saved when form is closed
If you already have an event that opens the form, try to just clear the filter property after it opens. You can do this from all your command buttons by just changing the form name that gets passed to it
Private Sub OpenUnfilteredForm(strFormName as String)
Dim frm As Form
DoCmd.OpenForm (strFormName)
DoEvents
If CurrentProject.AllForms(strFormName).IsLoaded Then
Set frm = Forms(strFormName)
With frm
.Filter = ""
.FilterOn = False
End With
End If
Set frm = Nothing
End Sub

Microsoft Access can't open a form from inside another form with doCmd.OpenForm

I'm completely new to MS Access but not to databases. I have a form that is meant to open another form through a button and users are to add records to a target table through said form. The main menu fails to open my secondary form saying "recordset is not updatable". The table that is to receive the records is editable and I can go into it and manually add records so this doesn't seem to be the problem. If I click out of the error through the error handler menu I'm taken to the form that I expected to open, but it is read only-- I can't see it's properties sheet, design view, or even change the view at all. I looked at the VBA code on the main menu and it does use doCmd.OpenForm "myForm", , , , , ,"New"
Any pointers would be really appreciated.
Right click your form and click design view. Add a button, click Cancel and name the button appropriately. Than, right-click the button and click Build Event > Code Builder > OK. Copy/paste the code below into the button click event.
Private Sub Command0_Click()
DoCmd.OpenForm "name_of_your_form"
End Sub
That should be all you need to do. Sometimes I have seen Access do some really weird stuff. If the steps I outlined here don't work, try doing a Compact and Repair to reset everything in your DB, and then add the button.

MS Access database close, ignore form close cancel true

I created a MS Access database with multiple forms. One of the form is a switchboard that leads to other forms. I wanted to make sure that the switchboard form never closes. So in the switchboard form I did:
Private Sub Form_Unload(Cancel As Integer)
Cancel = True
MsgBox "You cannot close the switchboard"
End Sub
However, I realized that when a user wants to exit the database using the close database at the top it triggers the message box above. I understand why this happens as Access probable tries to close all of the open window before closing the database.
Is there a way to change my vba to understand that the form close is coming from database close event. Or is there any better way to prevent form close?
There are several way and everyone preferes different way of achieving this. As for being user-friendly, if the user wants to close the database they should be able to. So instead of saying you cannot, why don't you just ask Would you like to close? if yes allow them to close.
2> If you really want to prevent them closing the form, why don't you remove all close buttons, borderStyle=none, closebuttons =false maybe poup = true?

How to change the order of open "tabbed forms" in MS Access via VBA

I am using "tabbed document" forms in MS Access (each main form that is open has a "tab" to allow users to easily move between forms).
Does anyone know of a way to reorder such opened forms via VBA? I have workaround code that closes all the forms and then re-opens them in the order I need, but it is clunky and slow (some of the forms are big so take a while to load, and often users have applied filters/sorts which I then need to individually re-apply, plus resetting the current record etc etc).
As all I need is to change the order of the forms on-screen, so my approach seems like overkill - but I can't seem to find info on how to do this anywhere!
(FYI I am NOT talking about the order of pages within a tab control, to avoid any confusion!)
Please attached screenshot with three tabbed forms open, I'd like to re-arrange them so eg left to right they become: #Home, Booking Detail, Enquiry Detail
Thanks
Ok, I have inadvertently figured this out.
In testing I found that if you hide a tabbed form, when you unhide it, it doesn't show up in the same position, but in fact now shows as the last form (ie the rightmost tab)
Eureka! Now to reorder the forms I simply hide them, and then unhide them in the order required. Combine this with DoCmd.Echo = False and there is, in my testing, virtually zero overhead.
Phew!
If the user is not seeing all the forms at once, you don't need to waste resource/time loading all forms at once. Load only what the user supposed to see. NavigationControl is very good for that.
Method 1
Move from tabbed documents to NavigationControl. Each tab is loaded OnDemand hence your main form start-up would be much more quicker. If the main and tabbed form are related to each other, use tabbed form's OnOpen event to dynamically change the record source.
I.e. Form_Open => me.RecordSource = Select * form T1 where T1.id = ParentForm.Id
Method 2
If you can't move to Navigation control, simulate the same effect as above.
When tab pages are changed/selected => underlying form gets a record source.
I.e.
Private Sub TabCtl2_Change()
If Me.TabCtl2.value = 1 Then
me.subform1.recordsource = source
me.subform1.LinkChildFields = linkingFieldName 'if related
me.subform1.LinkChildFields = LinkMasterFields 'if related
ElseIf Me.TabCtl2.value = 2 Then
'Your other form
end if
End Sub
This can help you to reduce your loading time.
[Cascading result sets]
In case if all of your forms are showing cascading results, you might want to consider remove record-source for all of your subforms and then re-apply at each selection.
The goal is to minimise loading time and show only necessary data the user is supposed to see/want to see. Hope this helps to have some idea.

Visual Basic Opening A Form [duplicate]

I have a login form which I need to close without the entire application being terminated. I tried using Me.Close() , Me.Hide() as well. The login form is used as the main form as well.
I hope this makes sense....
It sounds like you have a VB.Net project and your Login form is your 'startup form'. When you close that form, your application thinks it is over; but you really want to take action after the Login form is closed.
If you bring up the Properties window for the project, on the Applications Tab you can set the 'Shutdown mode'. The default is when the 'Startup Form Closes'. Change it to 'When the last form closes'.
You can also add Application level events here.
http://msdn.microsoft.com/en-us/library/f2bys999(v=vs.80).aspx
If you stick with the way you are going; your Login form is going to have to create another form before it closes or your app will close. You can do that; but it's probably cleaner to move the login logic into the Application Startup Event (see link for more details).
In the startup event you can show the Login screen, get the result, decide if you want to show the main form for your application, etc, etc...
This depends on where you are trying to close or hide the form. If you are trying to close or hide the form from within the the form itself then Me.Close() and Me.Hide() does the job. If you are attempting to close or hide a form from another form like your main form then you must refer to the form instance example:
frmAbout.Close()
frmAbout.Hide()
I hope this helps.