I have the following function that I found online. Unfortunately I can't remember where I got it since I've had it for a little while. Today, when I tried to actually put it to use it didn't work.
I'm calling it from a form as follows: CompactDB (tblHotword)
tblHotword is just a random table from the back end. My understanding of the function was that it would use that table to connect and get the file name of the back end.
Whenever I run it, Access pops up a window that says "Object required" and nothing else. It doesn't look like a standard error message popup. When I click 'OK', Access continues with the rest of the code as if nothing went wrong. The function doesn't run though.
Code: Public Function CompactDB(TableName As String) As Boolean On Error GoTo Err_CompactDB Dim stFileName DoCmd.Hourglass True stFileName = db.TableDefs(TableName).Connect
"how to COMPACT the DB by introducing delay of 10 seconds and then close the DB".In the Database, I'm able to accomplish the "Compact" the database using the function below.
Function Compact() SendKeys "%(FMC)", False End Function
As my DB is quite huge, the Compact action takes around 10 seconds to complete.Now, i would like to Close the Database after Compacting the DB. I tried including "DoCmd.Quit" in the function. The commands in the function, closes the DB but the Compact function doesn't seem to have executed as it needs 10 seconds to complete.
Function Compact() SendKeys "%(FMC)", False DoCmd.Quit End Function
how to introduce this delay of 10 seconds and then close the DB.
I want to find out how I can write VBA to find out if a default browser is open to a particular webpage. I guess I'm going to have to find the browsers handle but I also don't know where to go from there.
The code below opens a PDF selected from a form. Whatever document number appears in the textbox (FICNo) on the form is the document that is opened when the command button is clicked.It works but I would like to add a message box to say File not found if the document number in the textbox has no corresponding document in the folder (ScannedFiles).
Code:
Option Explicit Option Compare Database Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Sub CmdOpenDoc_Click() ShellExecute 0, "Open", "C:UsersDavid.BallDesktopScannedFiles" & Me.FICNo & ".pdf", vbNullString, "C:", SW_SHOWNORMAL End Sub
I am using Access 2010...I am suddenly getting the error 3048: Cannot open any more databases...The error occurs on the line of code: Set db = CurrentDb()
Code:
Private Sub SetInUseFalse(TelesalesId As Long) Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb() Set rst = db.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId) Run Some Code
[code]....
Why should I suddenly get this error? The error appears to be in a loop. If I close the error message, it pops up again. I have to close the database using Windows Task Manager.Is there a maximum number of connections? But I religiously close connections as indicated above!.I am only connecting to the current database (backend form frontend)Am I opening / closing connections & recordsets correctly?
I have a list box which contains different types of log entries. Each different log entry type has a different report that goes with it.What I want to do is select an entry in the list box, and click on print, email, pdf or view report buttons, and the appropriate happens, selecting the associated report for the log type automatically.I have a table with the logtype in it, and against that I have a DefaultReport field, which contains the name of the report that needs to be opened for that logtype.
I am getting the correct name for the report no problem at all, I have made sure that the name is right by going to rename report and copy and pasting it.When it goes to open the report I get an error message - Run-Time error 3071, the expression is typed incorrectly or is to complex to be evaluated.I have a debug line running to make sure I am pulling back the correct report name and I am.I have tried putting the dlookup where the report name would normally go in the docmd.openreport and I have also tried using ReportToView as a String and putting that in the docmd.openreport, but to no joy.
I have tried it with and without " around the report name and still no joy, either in the table or by concatenating the dlookup with Chr(34) at either end of it, then it comes up saying the report cannot be found.
I am trying to open a database with a password (I know the password) from another database however I cannot work out how to do it. I have been using this code to do this to open databases without passwords for a while.
I am using Access 2007.
Code: Private Sub Command36_Click() Const cstrClientFEPath = "G:Templates" Const cstrFEFile = "db.accdb" Dim intX As Integer 'Utility var
I am using the following event code to open a database from another. Everything works fine but, I would like add a mxgbox letting the user know the database does not exists and to contact me for assistance.
Private Sub cmdOpenTime_Click() Dim accapp As Access.Application Set accapp = New Access.Application accapp.OpenCurrentDatabase ("c:PILOT_ApplicationTIME.Accdb") accapp.Visible = True End Sub
In my frontend code, I include a table with a version #. In my backend, I also include a version table. The front end will compare wih back end, and if it's different, it will force to get the updated version that it's stored in the LAN.
However, I do not want the user to open the file directly from the LAN because it might cause slow performance problem if multi-user,etc.
So I want to implement a code to force the application to be open only from desktop.
So far, I have a strUsername which detect the user network environ. Then, it will check the application path to determine if it was opened from:
C:Users<strUsername>Desktop
If not, then an error message will prompt to alert the member to copy the file in the LAN and save on their desktop.
It works on my laptop, all fine. Today I didnthe test in my user desktop, but the message saying that the file has to be opened from desktop keep appearing.
I double check the user folder and the Username environ is (cd98) but the user folder was setup as "CD98" capital letter. Does that affect the coding?
How can I make my code to not distinguish between lower or upper case either for username and folder user as well?
I want a user to enter a number into an input box and then based on the number in this box a form will be opened with records associated only with that employee number. (All employee numbers are stored as text)The code below opens the form, but it is blank.
Private Sub cmdOpenAddKeys_Click() Dim EmployeeNumber As String EmployeeNumber = InputBox("Please Enter Employee Number:") DoCmd.OpenForm "frmAddKeys", acNormal, , "[Forms]![frmAddKeys]![empno]=" & EmployeeNumber End Sub
I have a query that opens a listbox in a form. In the listbox I want to add a doubleclick event that opens a pdf document with the selected record in it. The record is in column 1 of the listbox.
I can't use the FollowHyperlink method of the colecction application due the record in the column is a Key. I am not sure if FollowHyperlink method can be used in a listbox
I have been checking codes in the web and I found this:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long ShellExecute Me.hwnd, "open", "D:SebDesktopGA-BDpdf est.pdf, "", "", 4"
However, I don't know how to organize the code in a logic way in Sub End Sub. Neither I don't know if the code is for the doubleclic event in the list box or a Module. If is for a module I don't know how to write the code in it.
I have a workbook which is already opened and I want to close it. the code that i have is (see below) is not working.
Code:
Function CloseExcel(sExcelFile As String) As Integer Dim XLapp As New Excel.Application Dim ObjXL As Excel.Workbook On Error GoTo ErrorTrap Set ObjXL = XLapp.Workbooks.Open(sExcelFile)
I have a Database with a field that holds several attachments. I want to make a command button for a form that will open the attachment window that pops up when you double click on the attachment in the table. attach_fig7(1).gif.. I'd like the above window to open when I click the command button.
I'm having a little trouble getting this accomplished. I can instruct access to print the report, however I just want to be able to view the report after I select a button. I will attach a picture so you can see what I have thus far. I do have an older version of this and it works flawlessly and as far as I can tell everything is a carbon copy of the working version.
I want to open the dropdown box on my datasheet view subform from the main datasheet view form when I run over it with the mouse.From my main form textbox [WelderID]I tried this code but doesn't work. I get the error invalid reference to the property Form/Report.
Private Sub WelderID_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) Forms![Main]![WorkOrder Form]![DrawingNo fm]![Welds fm]![WelderStamp Sfm]![WelderStamp].SetFocus Forms![Main]![WorkOrder Form]![DrawingNo fm]![Welds fm]![WelderStamp Sfm]![WelderStamp].Dropdown End Sub
I am not sure if there is more code to use to open the subform in the datasheet view.
I have a list box that displays records. When i double click a record it opens the form needed.However I want it to open the form but default to a specific tab. But when it goes to the tab, the subform within it needs to match the ContractID of the record they double clicked on in the search form?I currently have this which opens the Client Form based on the ClientID of the listbox query search results and the client id of the main record.
Code: Private Sub SearchResults_DblClick(Cancel As Integer) If CurrentProject.AllForms("frm_Clients").IsLoaded Then DoCmd.Close acForm, "frm_Clients" End If DoCmd.OpenForm "frm_Clients", acNormal, , "[ClientID] = " & Me.SearchResults.Column(0)
So in theory If doubleClick then open Client Form on Tab3 where subform Contract field ContractID is matches the ContractID in on the search results?
hopefully you'll be able to help me out with this one, been searching but can't find the exact answer.
I am running a database with multiple users, max of 10, currently the database autocompacts when it is closed, however this takes time every time anyone closes it.
what i am looking to do is have the database automatically compact but only once a day. Any ideas???
My application relies on whether Outlook is open and more importantly, with the correct Exchange profile selected. To ensure this I have the following code which, on the work PCs (Windows XP and Office 2003) works correctly.
Code:
If Outlook_is_Running = True Then Set myOlApp = CreateObject("Outlook.Application", "localhost") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set colFolders = myNameSpace.Folders On Error Resume Next
[code]....
The work PCs are being upgraded soon to Windows 7 and Office 2007 so I have taken the application home and started to develop it on my home PC (Windows 8.1 64 and Office 2013 64). I have used PtrSafe where necessary and have compiled with no errors, but this code always returns false even though Outlook 2013 is open.
On further investigation, if I comment out the 'On Error Resume Next line I get the error Active X component cannot create the object (or similar) Error 429. This is the same regardless of whether Outlook is open or not
I have a form that is opened as hidden when my startup form loads. Data gets entered into it from other forms so whenever I switch records the hidden form needs to be opened to the matching record.
To accomplish this, I have been using the DoCmd.OpenForm in the OnCurrent event with the WHERE clause matching the PK/FK. I have had no luck with the SearchFor method.
It seems silly to have to keep reopening a form to go to a specific record when the form is always open already. Plus, I am wondering if it is affecting the forms' load times.
I want to open different .doc files by a button from access.
I want that the vba code checks where the current access database is located. In which folder the the current access database is.
In this file folder i have a folder called documents.
In this folder i have the .doc files.
Right now i have the following code.
Public Function getPath(ByVal iPath As String) Dim fso As Object Dim drive As String Set fso = CreateObject("Scripting.FileSystemObject") drive = fso.GetDriveName(CurrentDb.Name)
[Code] .....
The access database is in the folder Z:BUS MMM CGrimmMasterarbeitDatenbank
Which continues as is for 10 or 11 queries named in a similar pattern, then prints a report. However, as the number of append queries is not set (they are generated in a different quantity for different purposes, it's complicated), I am not sure how to check how many there are with that style of name.