Printing to Dymo LabelWriter 450 from Access VBA - mysql

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!

Related

File Dialog error access VBA

I am trying to have the file dialog box pop up so the user can select a file path to export a file in VBA but for some reason it throws this error on the following line of code.
Error: Method 'FileDialog' of object '_Application' failed
Code: longResult = Application.FileDialog(msoFileDialogFolderPicker).Show
All Code:
If choice = 6 Then
Dim intResult As Long
Dim strPath As String
'the dialog is displayed to the user
longResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
'dispaly message box
Call MsgBox(Application.FileDialog(msoFileDialogFolderPicker _
).SelectedItems(1), vbInformation, "Selected Folder")
End If
Else
End
End If
I am really unsure how to fix this issue. I checked my syntax and everything.
I know that this is a bit of an old question at this point, but since it doesn't actually have the answer, and I needed one today, I'm going to chime in with what I found just in case anyone else needs the answer too.
To fix this you need to add a reference to "Microsoft Office [yourversion] Object Library" in Visual Basic Editor >> Tools >> References...
The dialog in question should look like this:
Was trying to do the same thing myself and found this question. I realize that it is over a year old.
Try using the actual number (4) instead of msoFileDialogFolderPicker, that worked for me. I think something needs to be installed for the msoFileDialog constants to be initialized, when I tried printing any of the constants defined in the help file in the immediate window nothing was printed.
Also, why does your code have one variable longResult and one variable intResult?
Almost nothing is an integer in VB6 as integer is a VB4 16 bit type. Win32 Integers are called Long in VB6/VBA.
This was to make porting 16 bit code to 32 bit easy.
Check out http://msdn.microsoft.com/en-us/library/office/ff865217%28v=office.15%29.aspx for more information on proper syntax with FileDialogue.Show method. It appears you need a Set in front of your variable.
If you are after some cool UI, you can checkout my Github for sample database using .NET wrapper dll. Which allows you to simply call a function and to open filedialog with file-drag-and-drop function
Dim FilePaths As String
FilePaths = gDll.DLL.ShowDialogForFile("No multiple files allowed", False)
'Will return a JSONArray string.
'Multiple files can be opend by setting AllowMulti:=true
here what it looks like;

MSAccess 2010 + VBA: Value is not a default property of recordset Field object

I needed to copy some values from MS Access table into Excel using VBA code. I had done this many times and considered myself experienced. In my code I export the data using the following statements:
sh.range("A" & row).Value = rs("MyField")
where sh is Excel sheet, row is integer (long) and rs is recordset (either DAO or ADO, without any effect on the problem under consideration).
My code worked well on my computer with installed MS Office 2007. But when my client ran the code on his machine with MS Office 2010, it failed and kept failing very randomly. E.g. when debugging VBA in MS Access module step by step by pressing F8 it always worked. But when I pressed 'run' F5, it failed very soon.
After many trials and errors (I tried to open the recordset using different options and recordset types and caching the records etc.), I finally found that if I write
sh.range("A" & row).Value = rs("MyField").Value
everything works just fine. But according to the docs (e.g. http://msdn.microsoft.com/en-us/library/office/ff197799(v=office.15).aspx ) the Value property is the default property of the field object, which in turn is the default collection of the recordset object.
But it seems that I cannot rely on the defaultness, which I have been doing in most of my code. Actually I found a solution to my problem, but I still have no idea about the cause. Does anyone know why is the code doing this? What is the problem?
PS: I also found that if I expand the one-line statement into two lines (three with declaration):
dim v as Variant
v = rs("MyField")
sh.range("A" & row).Value = v
it also works...
Since rs("MyField") is a Field object, if you do ...
MsgBox TypeName(rs("MyField"))
... Access will tell you its type is Field.
So TypeName() is one example where the object itself is referenced directly instead of its default .Value property.
But something like Debug.Print always references .Value, so Debug.Print rs("MyField") is the same as Debug.Print rs("MyField").Value
If you know exactly when .Value will be referenced implicitly and when it will not, you can add it only when absolutely required and omit it the rest of the time.
However, some Access developers recommend always including .Value to avoid such confusion. If that seems like too much effort to you, at least consider including .Value when you do any assignment ...
something = rs("MyField").Value
... and be watchful for any other contexts where you don't get what you want without .Value

How can I check if an attachment field is empty or not in Access?

I am having some trouble with MS Access 2010. I am trying to modify a database I downloaded, a template from Microsoft‘s web site, I am doing a little modifying to keep track of the food nutrition. I have some experience with basic from the old days of the 16 bit Atari days. I’m not totally green to VBA, just know enough to get in trouble. I have a Form that uses a select query to populate lower half of the form. I added an attachment field to the foods table which has over 8500 record that is the table for the query. My problem is to add VBA code in a module to see if there is a photo present or not. I want to be able to show an icon grayed out for no photo and a regular icon if there is a photo file. But that's for when I get it work to begin with. I call the function in the field properties:
Photo1: chkAttachment([Photo])
This one to start with gives me and error saying: "The multi-valued field '[Photo]' is not a valid in the expression 'chkAttachment([Photo])'. When I change it to:
Photo1: ChkAttachment([Photo].[FileName])
I get and #Error for the empty fields and a "Has Photo" for the one with a file in it.
The Following code is the function I am referencing To Show what I am trying to do
Public Function chkAttachment(fldPhoto As String) As String
On Error GoTo chkAttachment_Err
chkAttachment = ""
'Debug.Print fldPhoto
If fldPhoto = Null Then
chkAttachment = "No Photo"
Else
chkAttachment = "Has Photo"
End If
chkAttachment_Exit:
Exit Function
chkAttachment_Err:
MsgBox " It don't like Error number: " & Err.Number & " " & Error$
Resume chkAttachment_Exit
End Function
The query won’t even call the code if the attachment is empty. I Googled the following question, and searched on this web site “Microsoft Access 2010 VBA how to query attachment field” without any luck. I have tried to use some code to count the number of files in the attachments, I found in the thread “How to query number of attachments from Attachment field in Microsoft Access?” from Aug 2011, but couldn’t figure out how to get it to work. When it comes to SQL, I’m in the dark with that part.
Thanks for any help that comes my way.
Steven
If you have an Attachment control named [attachPhoto] on your form and that control is bound to the [Photo] field (i.e., the Control Source of the Attachment control is Photo) then you can just check the value of
Me.attachPhoto.AttachmentCount
to see if the record has any attachments.
(Note that if you don't want the users to actually see the [attachPhoto] control you can just set its Visible property to No.)
You can check it in SQL statement " Not (tblxx.Pic.FileData) Is Null " probably in the where clause. I did it this way using a recordset.
I believe this is causing the #ERROR in your field
If fldPhoto = Null Then
Correct checking for Null would be the following:
If IsNull(fldPhoto) Then
But then you might still get a Null exception while calling the function. So you might want to edit your overall code to the following:
If (fldPhoto = "") Then
and when calling the function :
Photo1: ChkAttachment(Nz([Photo].[FileName]))
Hope I helped
I wanted to check if an attachment was made or not before running a query on a form. I made a text box in the form and under control source of the text box, went to expression builder and entered " = [name of column which has the attachment].[AttachmentCount]".
The text box gave me the count as 0(zero) if no attachment is made and 1 for 1 attachment. I could use the text box to condition run my query. All the above in Access 07.

How to search through VBA code files

I just started a job with a new company where previous developers had created many automated tasks. Of course, there is virtually no documentation and I didn't have a chance to work with the previous developer so now I'm trying to sift through all these processes looking for one that modifies some specific files.
I've scripted all the stored procs in SQL and used a search tool and didn't find what I was looking for, so now I am wondering if the process I need is located in one of many Access databases that are used. With SQL Server, it was easy to write a C# app to script the procs so I could search through them, but with Access it looks like I'm confined to opening each db individually to search through the code files.
Is there any way to programatically search through VBA code files?
If your interest is searching code modules in an Access database file, you can use the VBE object model. This sample searches for a word in all the modules of the ActiveVBProject of the current database. If the database includes more than one VBProject, you can enumerate the VBProjects collection and search the projects one at a time by name:
For Each objComponent In Application.VBE.VBProjects(ProjName).VBComponents
Or if you prefer to reference the project by number rather than name, just be aware the numbering starts with 1 rather than 0.
Public Sub findWordInModules(ByVal pSearchWord As String)
'Dim objComponent As VBComponent
' VBComponent requires reference to Microsoft Visual Basic
' for Applications Extensibility; use late binding instead:
Dim objComponent As Object
Dim strMessage As String
Dim strModuleList As String
strModuleList = vbNullString
For Each objComponent In Application.VBE.ActiveVBProject.VBComponents
If objComponent.CodeModule.Find(pSearchWord, 1, 1, -1, -1) = True Then
strModuleList = strModuleList & "; " & objComponent.Name
End If
Next objComponent
strMessage = "Text '" & pSearchWord & "' found in "
If Len(strModuleList) > 0 Then
strMessage = strMessage & "modules: " & Mid(strModuleList, 3)
Else
strMessage = strMessage & "no modules"
End If
Debug.Print strMessage
End Sub
Review the Access help topic for that Find method; you may prefer different options than I used.
If you want to target multiple db files and search the modules in each, you could automate this using the OpenDatabase method. I'll leave the details of that part up to you.
Another option, not previously mentioned - is to just print the Project Code, from the context menu, in the VBA Editor. The steps below, can be modified, to suit applications available, but the result is the same - searchable text.
From the VBA Editor, right click the project name, and click print, from the context menu that appears. Make sure "Code" is checked, and click "OK". The printer can be changed, from the "Setup..." menu, available in the last dialog.
On a side note - stand alone modules, SQL, tables, etc, are available for printing, from the "Database Documenter", in the "Analyze" group, of the "DATABASE TOOLS" tab.
Very useful, for sorting and outlining underlying SQL, of Access queries.
Best to download the free MZ-Tools for VBA and use their search/replace function.
Edit
MZ-Tools for VBA is no longer available. The paid version works with newer office installations.

MS Access overflow when I change queries

Okay, I have built reports in MS Access 2007, and each report runs off of several (40+) queries. The queries are opening tables, subqueries, etc, and I don't think Access is closing them. I could be wrong, but for some reason I think this is causing the overflow.
But anyways, I am trying to figure out why it is happening all of a sudden, and what I can do to resolve it. I had the reports working fine when I just had a schema and some dummy data, but when the database was actually populated, the individuals who gave us the data created a few more look up tables, so now a typical query using 3 tables is now using 5.
Do you think this increase in look up tables (and therefore more objects being opened by Access) is the reason I am getting overflow errors, or could it be something else? Also, I don't know VBA, so are there any simple solutions (e.g. breaking up the reports, which would take a while) that would be worth pursuing?
Thanks
Make sure you really understand your "overflow" condition. This code displays "Error 6 (Overflow)", without the quotes, in the Immediate Window.
Dim i As Integer
Dim strMsg As String
On Error GoTo ErrorHandler
i = 32767
i = i + 1
ExitHere:
On Error GoTo 0
Exit Sub
ErrorHandler:
strMsg = "Error " & Err.Number & " (" & Err.description _
& ")"
Debug.Print strMsg
GoTo ExitHere
The explanation for that error is that 32,767 is the maximum value a VBA Integer can accept. So, attempting to add one would give 32,768 which is greater than an Integer can hold ... so overflow.
Other numeric data type also have limits. For example, 2147483647 is the maximum value which can be stored as a VBA Long.
I might be totally off base here, but I would check whether your complex report includes sorting and grouping options where perhaps you produce totals. And if so, whether the data you added pushes the values for any of those totals beyond the capacity of their respective data types.
If you're getting a different error message which includes the word "overflow", it might help to tell us the exact text of the error message.