Cannot close and reopen Form in Access (OLE Connetion) - ms-access

I'm a VBA noob but maybe you can help:
I want to refresh all Forms (subforms) and queries on my Main Form "FinalForm". However I use Access as a frontend to SQL server. So apparently the usual buttons (created with the wizard, like refreh, new record etc.) won't work.
I created a (stupid) workaround by closing and reopening the form:
Private Sub Befehl71_Click()
DoCmd.Close acForm, "FinalForm"
DoCmd.OpenForm FormName:="FinalForm"
End Sub
This works fine within the vba editor but fails if triggered by button (something about an ole communication error).
How can I fix this ?

The standard VBA procedure is
Me.Requery
For a subform only
Me.PUT_SUBFORM_NAME_HERE.Form.Requery

Related

MS Access - Command button wont function at all

I have tried to Google and review previous Stackoverflow posts but I cannot seem to find a solution and this seems like such a simple fix.
I put a Command button in my Form because i wanted to test exporting information within the form to an Excel spreadsheet.
Private Sub cmdExportFilename_Click()
Dim sFilename As String
sFilename = "C:\Users\Redacted\Desktop\exportResults.xlsx"
DoCmd.OutputTo acOutputQuery, "OpenComplaintsQuery", acFormatXLSX, sFilename, AutoStart:=True
End Sub
I made sure the OnClick event was set to [Event Procedure] but when i go into form view and click nothing happens not even an error so i feel like i am still missing something that is telling that button to run that code. i checked my Trust Center settings and changed it to enable code but still nothing.
Any advice is helpful!

How can I refresh my external data source (link to sharepoint) in Access vba?

Really struggling to find a solution to this.
I have an access form, which has a subform.
The subform displays, via a query, records from an external data source (a sharepoint folder). I need the external link to refresh automatically, ideally on load.
Private Sub Form_Load()
TableDefs![My External Table Name].RefreshLink
End Sub
didn't work neither did it without TableDefs!
I'm piecing things together with limited experience, this is my first dabble with access. I had the connection refresh off a macro in excel with
Sub Refresh_click()
Range("MyExternalTableName[[#Headers],[ID]]").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
End Sub
and that was fine, now in access I'm lost. I need this subform to be updated before using the rest of the form but could refresh off a button if needs be. I already use a refresh button as part of the form and this doesn't affect the external link unfortunately.

MS Access Office 365 keeps crashing when opening a popup form

I am using a windows 7 Enterprise 32-bit operating system and Microsoft Access 365 ProPlus.
I open a form then when I double click on a field it triggers an event procedure that opens another form. This form is a Pop Up form (non model) single form default view. Everything was working great for the last year or so and for some reason when I open the form this way the access program crashes.
I can open the form by selecting it from the search forms dialog.
What I found works is I need to open the form then edit it in design view. Make a small change in the form and save it. Then view it in form view and close the form. Once I have done all this I can run my program normally and everything works great until I close access and re-open it. Then I need to do it all over again.
I have ran the compact and repair tool several times.
My code is a very simple one:
On Error GoTo Err_Command18_Click
Dim intBuildingId As Integer
Dim StDocName As String
intBuildingId = Form_Frm_Buildings.Building_ID
StDocName = "Frm_Buildings_To_Frm_Manager"
Me.Refresh
DoCmd.OpenForm StDocName
Forms(StDocName).Recordset.FindFirst "Building_Id = " & intBuildingId
Err_Command18_Click:
Exit Sub
Any help would be appreciated and thanks in advance!
Mark

How to save an Access database using VBA program?

In order to save a record in my MSAccess database via a VBA application, I wrote the following. But when running the code it discards acCmdSaveRecord as an undefined variable. Can anyone give some leads about this?
Option Explicit
Private Sub SavingAccessDB()
DoCmd.RunCommand acCmdSaveRecord
End Sub
In the VBA Window, select Tools menu, then References...
Tick the checkbox:
Microsoft Access xxx Object Library

Running VBA code on an event in an Access web database

I took a already set up database from the Office.com templates (File --> New --> Office.com Templates), since this template already gave me 80% of my requirements.
I then changed the last 20% of this template where I came into the following: It seems as this template is a web database. I am not sure about the differences of a web database and a normal database in Access at all but I did find out, they do not allow me to run VBA code. At least not when I am trying to call it by an event.
Is there any way to achieve this anyways? Or are there possibly any other ways, such as converting the web database into a normal one perhaps?
Actaully, you can call VBA code from the forms event code. However, it requires a bit of a kluge.
However, you don't need to do this in your case.
Do note that you can create client objects and use client VBA code in your web application.
This means you can add/mix VBA forms into that application (these client objects of course cannot run in a web brwoser, but they can be used the client).
Suggestion #1:
to hide record navigation buttons.
Open the web form in layout mode. Move a object (dirty the design).
Whack ctrl-g for VBA command prompt. Type in this:
forms(0).NavigationButtons = False
Now, save the form. The record navigation setting will be saved with the form.
Suggestion #2:
Open the web form with VBA. Use this code:
DoCmd.OpenForm "AssetsDetails"
Forms("AssetsDetails").NavigationButtons = False
Suggestion #3:
Call VBA code from the forms load event. This is a bit of kluge, but does work:
In the forms open event, place this macro code:
OpenForm (frmRunVBA,,,Dialog)
Note that in above WEB MACRO editor the VBA form above called frmRunVBA does NOT appear in the drop down choice list - but you CAN TYPE/force in the name – this is legal.
Now create a VBA form called frmRunVBA). In the forms load event, palce this code:
Private Sub Form_Load()
Forms("AssetDetails").NavigationButtons = False
DoCmd.Close acForm, Me.Name
End Sub
So you can call VBA code, but you really don't need to if you use tip#1.