"Invalid Object Format Name" in Crystal Reports - vb.net

When working with Crystal Report Field Objects and attempting to set "EnableSuppress" to False or alter the position or width of a field object is generating an "Invalid Object Format Name" error. The debugger shows all my code running without error until attempting to actually load the report. At that point, it will run the first couple without problem, then it fails when messing with a field object, and none of the rest will run. The code is shown below. Everything that generates an error is a FieldObject, but not all fieldObjects generate errors. In the code below, everything in Section2 is a TextObject and everything in Section3 is a FieldObject.
If condition = True Then
'Lines marked as runs ok, only run when a line that generates an error is not present before it.
Report.Section2.ReportObjects("Text7").Left = 7830 'Runs ok
Report.Section3.ReportObjects("Field4").Left = 8085 'Runs ok
Report.Section2.ReportObjects("Text13").ObjectFormat.EnableSuppress = False 'Runs ok
Report.Section3.ReportObjects("Field28").ObjectFormat.EnableSuppress = False 'error
Report.Section2.ReportObjects("Text9").Left = 10830 'Runs ok
Report.Section3.ReportObjects("Field23").Left = 10830 'error
Report.Section3.ReportObjects("Field23").Width = 615 'error
Report.Section2.ReportObjects("Text10").Left = 11445 'Runs ok
Report.Section3.ReportObjects("Field25").Left = 11445 'Runs ok
End If

Unless you figure out what is different about the fields that throw errors and are absolutely set on formatting in VB code, I suggest that you do your formatting from within the Crystal report. You obviously know about the conditional suppression and to change size and location of a field you can right-clicking on the field and clicking "Size and Position". There is also an option for conditional placement (formula).
Hope that helps,
Chris

Related

Set X = Form.Recordset gives Run time error ‘13’: (Type mismatch)

In Access VBA I have written a routine (subform Click event) to display in a text box on the main form the contents of a field in the selected row of the subform, when the user clicks on a row in a subform.
I created a simple form/subform application to test the code and it works perfectly. However, when I port this code into the production application I am updating, I get error 13. My debug code shows that both variables (MyRsMF and MyFormMF.Recordset) are type 9 (Object). I have reduced my routine’s code to the sample below.
I accept that there is a difference between my test application environment and my production app. However, I have run out ideas and would be grateful for any suggestions as to how I can find the difference(s).
I am working with W10 and Access 365.
My code is:
Private Sub Form_Click()
'
Dim MyFormMF As Form
Dim MyRsMF As Recordset
' Get the Form's recordset
Set MyFormMF = Forms.TB.Form
Debug.Print VarType(MyRsMF) & vbTab & VarType(MyFormMF.Recordset)
Set MyRsMF = MyFormMF.Recordset <<----<<< Error 13 occurs here
Set MyFormMF = Nothing
Set MyRsMF = Nothing
End Sub

SAP status message error captured to automatically close

I am new SAP GUI scripting. I have a question regarding to how to stop SAP GUI script running if there's any status messages captured.
I recently create SAP GUI script recording and Excel macro for automation, so far, everything works very well if there's any data collected. However if there's no data collected and will have status bar then the script will become error.
So I tried to find a way to create some code if the status error show up, the script will automatically close, but seems like I only can make it work if the error is only for "No items selected (see long text)". However there are also other few status error will shown up as well, so I'm thinking to make the status bar captured the whole error if possible.
Hopefully you guys can help me regarding this in SAP GUI scripting,
thanks.
If session.findById("wnd[0]/sbar").Text = "No items selected (see long text)" Then
Exit Sub
End If
You can check for the messagetype of the status bar. If it is E then you've got an error.
Instead checking for the text like in your code you check for the messagetype
If session.findById("wnd[0]/sbar").MessageType= "E" Then
' Whatever code is needed here
Exit Sub
End If

How to make statement that does more than 2 if condition is completed?

I'm making a Windows vb.net form application in Visual Studio 2015, where user can either preview an image in a PictureBox by importing it from a file dialog browser, or from a web url. If the user chooses to import it from its computer using the file dialog, the preview will automatically load once it has selected the image file.
If user accidentally fills both url and file dialog, i want to clear the TextBox of the url (called url_cover), the TextBox displaying the name of file imported in file dialog (called Browse.FileName) and the PictureBox preview (called preview), and also display a MessageBox telling user to try again, using only one of the import options.
I've already tried making a basic if statement which (until there everything normal) :
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning")
url_cover.Clear() Browse.FileName = Nothing preview.Enabled = False
I was expecting all these things to happen if i filled both url and file browser, but i came out with an error telling me that an end of statement was expected after the second instruction (which is url_cover.Clear()).
I tried switching the order in which the three instructions had to be executed, but every time it was the same, after the second instruction, an end of statement was expected...
Hope my explanations have been clear, and my question is how can i execute more than 2 instructions after the condition of my If statement has been completed.
If you want more than one statement to execute if a condition is met, then you need to enclose it in a block that ends with End If.
Your code will only execute the messagebox if the conditions are satisfied and then try to execute the rest whether the condition is met or not. You're getting the End Of Statement Expected error because you're trying to put several statements on one line.
Try this ..
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], Warning")
url_cover.Clear()
Browse.FileName = Nothing
preview.Enabled = False
End If
Try this out... You can use : to separate statements if you want them on one line.
If Not String.IsNullOrEmpty(url_cover.Text) AndAlso Not String.IsNullOrEmpty(Browse.FileName) Then MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning") : url_cover.Clear() : Browse.FileName = String.Empty : preview.Enabled = False
Or block...
If url_cover.Text <> Nothing And Browse.FileName <> Nothing Then
MsgBox("Please do not import image using both file browser and URL.", [vbOKOnly], "Warning")
url_cover.Clear()
Browse.FileName = Nothing
preview.Enabled = False
End If
IMHO, look into String.IsNullOrEmpty, Multiple statements in one line and the AndAlso operator. Also try to avoid the :, if statements can become long, obscure readability etc, but nothing is wrong in using it.
Please consider adding a comment if you think this post can be improved.

How do I fix Error 432 when loading a form in Word VBA?

I have a Word .dot file which works in older versions of Word but fails with error 432 when run in Word 2013.
When I debug the code I have the line:
Load customerForm
And VBA shows the error:
Run-time error '432': File name or class name not found during Automation operation
The project "pennyscode" includes "Module1" which contains the function being debugged, "ThisDocument" and a form called "customerForm".
I have tried changing the name to "pennyscode.customerForm" but this doesn't make any difference.
This code is being called from a Sub function which is called from Document_New().
Updates
I can place a breakpoint on the Load customerForm line and demonstrate that it is the line that is causing the problem. If at this point I mouse over the word "customerForm" VBA comes up with
customerForm = <Object variable or With block variable not set>
If I delete/skip the Load line then the next line is customerForm.Show and that produces the same error.
If I just open the .dotm file and then use Alt-F11 to open VBA, I can look at the code for selectCustomer, list properties/methods and customerForm appears in the list.
Additional Note
I believe that within the Load function it must be calling GetObject and it is this that is failing. It is as if VBA can't find the customerForm object even though it appears in the project.
I've posted the full code of the function being called from Document_New below.
Sub selectCustomer()
Dim Doc As Document
Set Doc = Application.ActiveDocument
If Doc.CustomDocumentProperties.Item("Customer") = "Nothing" Then
Load customerForm
customerForm.Show
Unload customerForm
Doc.Fields.Update
a$ = Doc.CustomDocumentProperties.Item("InvoiceNumber")
a$ = customerForm.pathBox.Value + "\" + a$
Doc.SaveAs (a$)
End If
End Sub
I've also posted the full .dotm (Excel 2013) and .dot (previous excel) and some sample data (.xls) here:
Dropbox/Public/Invoice 2015-16.dotm
Dropbox/Public/Invoice 2015-16.dot
Dropbox/Public/data.xls
Update
I've not had much luck making progress on this question. Can anyone suggest an approach to investigating this? Or how I might improve the information on the question?
I finally managed to fix this, and I have a few learnings.
Firstly the debugger shows the error as occurring on the Load customerForm line, but this is actually not the case.
The customerForm has an _Initialize function which loads data into it before it is displayed. This function was failing with but the debugger stops on the wrong place.
I was able to debug this more effectively by putting a breakpoint on the start of the _Initialize sub and then stepping through the code.
Once I had discovered this I realized that the code was failing to find the XLSX file due to a wrong path, thus causing the run-time error.
Once I'd fixed up all the paths, I then hit a second error: runtime error '9' which is a subscript problem. This also reported on the Load customerForm line and was also due to a problem with the _Initialize function.
This was the true source of the problem, and demonstrated a functional change between Office 2013 and previous versions of Office.
My code was opening an XLSX file and attempting to read data from it:
Dim myXL As Object
Dim myWS As Object
Set myXL = GetObject("C:\Test\data.xlsx")
myXL.Application.Visible = True
myXL.Parent.Windows(1).Visible = True
Set myWS = myXL.Application.Worksheets("Customers")
The run-time error 9 was due to the index of the Windows property, as their were no windows. In previous versions of Office, there was a single window, with 2013 the array is empty.
After much messing about I tried adding this line:
myXL.Activate
before accessing the Windows() array. Once that was executed Windows(1) existed and the code worked as before.
Hope this can help someone else struggling with similar problems.

Method 'range' of object _global failed when doing nothing

I have a big macro which basically processes some columns and spits out results based on some cross-checking with an access 2003 database. It works absolutely fine - no hitches at all.
However, I recently had to make a modification to it. It was literally changing an '8' to a '9' in one line of the code. But next time I ran it, it threw the 1004: Method 'Range' of object '_Global' failed error. Excel 2003 is a funny thing - I once scratched my head for hours over this, trying to find offending lines of code that could be causing the error, but alas to no avail. I did something that I didn't expect to trigger anything:
Starting with the original macro (100% confirmed working), if I just open the code up, and then save it so the 'last updated' metadata will update to reflect the save, though absolutely nothing has changed, it will throw that error again on opening.
It's as if it's so fragile that saving the macro as is will break it. Any ideas?
Update: here's what I changed that initially brought about the issue
iOutputCols = 9 'this was changed to 9 from 8
ReDim Preserve sOutputCols(iOutputCols)
sOutputCols(0) = "Policy No"
sOutputCols(1) = "Client"
sOutputCols(2) = "Trans"
sOutputCols(3) = "Effective Date"
sOutputCols(4) = "ClosingRef"
sOutputCols(5) = "Gross"
sOutputCols(6) = "Comm"
sOutputCols(7) = "Net Due"
sOutputCols(8) = "Risk" 'this line was added
Making the change here, while originally causing the error, doesn't seem special - I did small changes like the above elsewhere in the code and in other modules, one time I even did something as testval = "test" and even that redundant line will produce the error. The most minimalistic way to cause it? Simply open it up, save it without changing anything, and on next use the error occurs.
The error occurs at this line, in a completely different code section which is part of a form:
If strErr <> "" Then MsgBox strErr, vbInformation + vbOKOnly, "Action Error"
Application.ScreenUpdating = True 'error occurs here, message box which shows me the error right above
End Sub
Update 2
Removing the error handling throws the error on this line
Case "> Send Next Period Reminder" 'error on line below
Call ReplaceText(wordApp, "[office_address]", Range("Address_" & Worksheets("UserParms").Range("F6").Value).Value) 'error this line
Call ReplaceText(wordApp, "[office_address2]", Range("Address2_" & Worksheets("UserParms").Range("F6").Value).Value)
'more of the same replacetexts below
For context, this is when an option is selected for "Send Next Period Reminder", which pulls a word .dot template from a static folder and populates it based on the data selected within the sheet (Hence the replace texts). This is in a different module and has never been touched before.
Try properly qualifying your Range method calls. You have lines like this:
Call ReplaceText(wordApp, "[office_address]", Range("Address_" & Worksheets("UserParms").Range("F6").Value).Value) 'error this line
Call ReplaceText(wordApp, "[office_address2]", Range("Address2_" & Worksheets("UserParms").Range("F6").Value).Value)
While it may not be obvious, there are cases, both environmental and code-based, where these unqualified uses of Range could fail. Change the references like Range("Address... to something like yourTargetWS.Range("Address...