Upgrade Access 2000 to 2010 then 2016 VB question - ms-access

Help please...I have successfully upgraded from Access 2000 to 2010 then to 2016 with no compile errors however I have an exe file within a form in the VB code and it doesn't run anymore or send an error message. The project is a weighbridge and has been operating on access 2000 for 15 or more years with many changes to the design, where the exe file captures the data from the weighbridge "signal" box and sends it to my form. This exe no longer works in Access 2010 (the go between program during upgrade) or in Access 2016. This is crucial to the project, I no longer have the original code in VB or a copy of VB on my computer although I do have a copy in a text file left by the original programmer. Can anyone tell me Why Access 2016 does not acknowledge this exe. Is there a reference that needs to be clicked? I am lost.
The code is
Private Sub Form_Load()
On Error GoTo Err_Form1
Select Case strDocName
Case "GetGrossWeight"
Set objFrmCtrl = Forms!ConsignmentsIN.GrossWeight
Warning.Caption = "Get Gross Weight In"
Case "GetTareWeight"
Set objFrmCtrl = Forms!ConsignmentsContractIN.TareWeight
Warning.Caption = "Get Tare Weight In"
Case "GetGrossWeightcontract"
Set objFrmCtrl = Forms!ConsignmentsContract.GrossWeight
Warning.Caption = "Get Gross Weight In"
Case "GetTareWeight"
Set objFrmCtrl = Forms!ConsignmentsContract.TareWeight
Warning.Caption = "Get Tare Weight In"
End Select
OpenEXE
Exit_Form2:
Exit Sub
Err_Form1:
MsgBox Error$
Resume Exit_Form2
End Sub
Private Sub OpenEXE()
On Error Resume Next
GrossValue = Shell("c:\weighbr\auto\Weight.exe", 6)
If Err.Number = 53 And GrossValue = 0 Then
MsgBox "Can't find program 'Weight.exe'", vbInformation, "Alert"
End If
' ...
End Sub

According to the documentation for SHELL:
Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.
Your code gets a task ID, not the result of executing the .exe program (if nothng else prevents execution). So, you shouldn't expect, in any case, to get a value generated by this program.
You should use the debugging tools to step into this Sub and actually figure out what it does.
Check if Alternative to Call Shell() ? (2000) can help you out, and also Access 2000 to 2002 (Shell command).
It seems that the Shell function might have changed a looong time ago.

Related

Printing to Dymo LabelWriter 450 from Access VBA

We've recently upgraded some PCs and have subsequently come across some issues with the VBA code in an Access frontend we use to perform operations on a MySQL database. The specific piece of code pulls a serial number from the database and then prints it to a Dymo Labelwriter 450 as a barcode.
Style = vbExclamation + vbYesNo
Title = "Print Label For " & Me.txt_Barcode & " ?"
Response = MsgBox("Do you want to print a label for serial number " & Me.txt_Barcode, Style, Title)
If Response = vbYes Then
Dim myDymo As Object
Dim myLabel As Object
'On Error Resume Next
Set myDymo = CreateObject("Dymo.DymoAddIn") '
Set myLabel = CreateObject("Dymo.DymoLabels")
If (myDymo Is Nothing) Or (myLabel Is Nothing) Then
MsgBox "Unable to create OLE objects"
Exit Sub
End If
The code now breaks at line 8, i.e.
Set myDymo = CreateObject("Dymo.DymoAddIn") '
The error code I was getting was relating to ActiveX (which seemed possible that it might relate to going from 32-bit to 64-bit), but since installing the latest DLS from Dymo (DLS8Setup.8.2.2.996), it seems to have evolved to the following:
Run-time error '-2147467261 (80004003)
Automation error
Invalid pointer
I'm hoping someone can point me to an easy fix so I don't have to totally re-write the code!
Thanks in advance!
I managed to resolve this one in a couple of steps and to be honest, I'm not sure which exactly fixed this specific part of the problem:
First was to run the DYMO_Label_v.8_SDK_Installer
I also switched from the latest Dymo Connect to DYMO Label v.8
I then had to ensure the Barcode font we're using was installed as an admin for all users, rather than just a specific user profile
and finally, and I think this may have been the kicker, the software was looking for a label template called 'Serial.label' which I found on our server and copied and pasted into the C: drive where the software was looking for it.
I'm just glad I didn't have to re-write the code!

Getting Error 3024 file not found for a mystery file not even used by the program? (dbo.mdb)

One user reported getting error:
3024 Could not find file ...\user\path\to\My Documents\dbo.mdb
But there is no file of this name needed nor referenced nor coded, nothing. I have no clue as to why the error would say this.
The error occurred somewhere during these three steps:
If IsLoaded("ApptDetails") Then
strStep = "Closing Appt Details Form"
DoCmd.Close acForm, "ApptDetails"
End If
If IsLoaded("NewClientDetails") Then
strStep = "Closing New Client Details Form"
DoCmd.Close acForm, "NewClientDetails"
End If
If iFormEdit = 1 Then
strStep = "Opening Appt Details Form, form Edit = " & iFormEdit
DoCmd.OpenForm "ApptDetails", acNormal, , , iFormEdit, , strOpenArgs
Else
strStep = "Opening New Client Details Form, form Edit = " & iFormEdit
DoCmd.OpenForm "NewClientDetails", acNormal, , , , , strOpenArgs
End If
Background:
Environment is Access 2010 on Windows 7 inside company network, back end SQL 2012 within the network.
Each user has a copy of the Access FE on their desktop and they get a fresh copy of the master each time they log in. This improved performance greatly. This database is heavily used.
My database was originally written in 2008, and has been updated as needed. Problems started being reported in July by multiple users. Prior update to database design was in Dec 2016. I upgraded the code to ADO and made fixes to syntax that I could find. Installed update 3 weeks ago, been running fine until today.
Any brilliant ideas out there would be greatly appreciated.
it could be one of your SQL that is calling wrong table.
i think that in access the dots in the SQL table names are renamed to underline or so.
try to identify when happends (after click, or on load, or something) and recheck your querys.
good luck

workbooks.close does not work for me

Hope someone can help with my following problem.
I want to make sure a specific workbook is closed before It gets an update.
for that I was planning to start with.
Private Sub Command1_Click()
workbooks("workbookname.XLSM").close Savechanges = False
End Sub
I also tried
workbooks("workbookname.Xlsm").close
Both i have run separately and both give me Error code 9.
The specific file will always be on the desktop of the user.
I thought it might have something to do with my references so I checked and have the following references turned on. (some for other specific reasons).
Visual Basic For Applications
Microsoft Access 16.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft Excel 16.0
Object Library Microsoft Scripting Runtime.
Really hope someone can help me with this. I've been surfing quite a large number of forums but no where i could find the same problem or solution.
w.k.r. Drac.
You have to check to see if it's open, and reference the open object properly. The function below (which I picked up off SO somewhere), returns a true/false value about the file in particular:
You would use it as such:
Private Sub Command1_Click()
Dim xls As Object
If IsWorkBookOpen("C:/Users/Desktop/Workbook.xlsm") = True Then
Set xls = GetObject("C:/Users/Desktop/Workbook.xlsm")
xls.Close True
Else
'do stuff if closed
End If
End Sub
Function:
Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long
On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function

MS Access rejects arguments, always asking for "="

I have used VBA to program MS Access for many years but never before with Office 2010. Whenever I try to use any arguments I get the message "Expected: =" after I close the brackets.
For example, a simple messagebox accepts the caption but will only produce the default argument (vbOKCancel). In some circumstances I would prefer to use vbYesNo but if I enter MsgBox("Do you wish to cancel",vbYesNo) then although the various alternative responses drop down for selection, I get "Expected: =" on trying to complete the statement. This happens whenever I try to use arguments - for example if I use DoCmd in the OnCurrent event of the Form object to display a particular record.
Example code:
'If closed without a preference being selected, continue:
If IsNull(cboPreference) Then
MsgBox ("You have not selected a preference. Do you want to cancel?",vbYesNo)
Select Case Response
Case vbYes
Exit Sub
Case vbNo
cboPreference.SetFocus
End Select
End If
I have tried uninstalling and reinstalling the application; but the error occurs both in Windows 7 on my PC and Windows 8 on my laptop (both 64-bit).
I have also installed the latest updates for MS Access 2010. What else can I do?
Test these two statements in the Immediate window to see the effect of the parentheses.
MsgBox("Do you wish to cancel",vbYesNo) ' complains about expected =
MsgBox "Do you wish to cancel",vbYesNo ' this works
If you want to capture the value returned from MsgBox, assign it to a variable ... and you need an equal sign and the parentheses in that situation.
Response = MsgBox("You have not selected a preference. Do you want to cancel?",vbYesNo)
More about when to use parentheses with a function call, and when not to use them ...
MsgBox "Hi"
Call MsgBox("Hi")
intResponse = MsgBox("Hi")

Running VBA macro within Access 2010 from external VBScript

Not sure this is possible, but it seems like it should be doable.... it is 2013 after all! And some forum posts I found suggest it is, but I have not been successful in getting it to work...
I have an Access 2010 db with a macro that downloads files from 3 different web sites and then proceeds to import the data and process it. It runs for 1hr and 17 mins.
I want to schedule this macro to run at 4am so it is all done and dusted by coffee time and work start 8am... So I created a VBScript to run this, which will then be placed into the Task Scheduler for the desired time.
It is a single user DB, my use only on my PC.
I have done some research but I cannot seem to get this working. Here's what I have so far:
Macro inside "Main" module in Access 2010 inside of "Pricing Model.accdb":
Public Sub Download_And_Import()
ProcStep = ""
ExecStep = 1
DoCmd.SetWarnings False
'Empty the Execution Progress table
DoCmd.RunSQL "DELETE * FROM EXECUTION_PROGRESS"
Call Update_EXECUTION_PROGRESS(Format(Now(), "YYYY/MM/DD HH:MM:SS"), ExecStep, "Starting Download_Files Main Procedure...")
Call Download_Files.Download_Files
Call Update_EXECUTION_PROGRESS(Format(Now(), "YYYY/MM/DD HH:MM:SS"), ExecStep, "Finished Download_Files Main Procedure...")
Call Update_EXECUTION_PROGRESS(Format(Now(), "YYYY/MM/DD HH:MM:SS"), ExecStep, "Starting Import_Files Main Procedure...")
Call Import_Files.Import_Files
Call Update_EXECUTION_PROGRESS(Format(Now(), "YYYY/MM/DD HH:MM:SS"), ExecStep, "Finished Import_Files Main Procedure, closing application now...")
DoCmd.SetWarnings True
End Sub
I then created the following VBScript to run Access VBA Macro externally:
dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("G:\Pricing DB\Pricing Model.accdb")
accessApp.Run "Download_And_Import"
accessApp.Quit
set accessApp = nothing
I get the message "Illegal function call, Line 4" which is the step:
accessApp.Run "Download_And_Import"
Any ideas / help is highly appreciated! Thanks in advance!
M
I don't see anything wrong with the VBScript itself. I copied your code, changed the db file name and procedure name, and it ran without error. So my guess is the VBScript error "bubbles up" from Access when it tries to run the procedure.
Open Pricing Model.accdb in Access, go to the Immediate window (Ctrl+g), type in the following line and press Enter
Application.Run "Download_And_Import"
If that throws an error you surely have a problem in that procedure. If it doesn't throw an error, you could still have trouble running it from a scheduled task if the procedure requires Windows permissions and you haven't set the task to run under your user account.
If you need to troubleshoot the procedure, first add Option Explicit to the module's Declarations section. Then run Debug->Compile from the VB Editor's main menu. Fix anything the compiler complains about. Repeat until the code compiles without error.
Disable DoCmd.SetWarnings False during troubleshooting because it suppresses information. Consider whether substituting the DAO Database.Execute method for DoCmd.RunSQL will allow you to avoid turning SetWarnings off at all.
You could try including the ProjectName:
accessApp.Run "[Pricing Model].Download_And_Import"
The project-name defaults to the database name, and square-brackets are needed because of the spaces.
This shouldn't be necessary, because your Sub is Public, but worth a try.
I ran into the same (msg) issue the script was OK! Problem was i was testing the script with the database opened as I was in development mode, as soon i closed the Database the script worked well.Close the database before testing the script.