Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Ok. Here it comes. Comments are welcome. Please confirm you have the updated file cz can be messy when you have a lot of file with similar name. Cheers
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Okay this should give you stuff to work on. Attach the project again when you are satisfied with it.
1 In CPSystems you have Me.MousePointer = vbHourglass followed immediately by Me.MousePointer = vbNormal. If there was some long-running code between them then it would make sense to use them but as it is now it does noting for you.
2 IMO the text on cpsystems is too large. Also it should say "…15589 Parts 1 and 2" or "…15589 Part 1 and Part 2"
3 The CPSystems.Show line isn't necessary
4 Using the menu of CPSystems I can open the onshore and offshore forms at the same time. Do you want that?
5 I can't move the CPSystems form using the mouse. Why is that?
6 You should add the following code to CPSystems to ensure that all forms are closed when you exit this form
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next
End Sub
7 When you tab through the fields on offshorecpsystems (which I'll refer to here from now on as offshore) and you tab out of cmdcancelform, the frame for the bracelet anode shows up which is something that you probably don't want to have happen.
8 In offshore you have MsgBox "Please make a selection" for an empty textbox. While that's a good message for a combobox you should probably change it to MsgBox "Please enter a numeric value". You also have MsgBox "You must enter numeric value". I think something like MsgBox "Please enter a numeric value" would be better.
9 I can put values like 99999999 and -1 in the textboxes. Is that valid? If there are valid ranges you should validate such textboxes for the range. You can do that in the Lost_Focus event of the textbox. If there is no specific range you might want to check for reasonable values. For example while a pipe could be 99999999 meters long, that's probably not reasonable so you should ask an "Are you sure?" type question
10 In offshore and onshore you have a series of 3 Msgboxes that begin with "Prepare Plans and Specification". I, After a while using the app I would be annoyed at having to see and respond to those 3 messages every time I did a calculation. You could do something like the following instead. There is also a way to have a 'don't show this message again' option. If you're interested and need help with that let me know.
11 When you have the same code in two or more forms it's a good idea to create one Public Sub in a module and call that sub instead of having to maintain duplicate code.
12 What are you trying to say with "Select Alternative Cathodic Protection System"?
13 Do you really need to tell the user to "Exit Program"?
14 What are you trying to tell the user with "Select Alternative Cathodic Protection System"
15 For my own information, how do you tell if this "Is this the most economical alternative?"
Last edited by MartinLiss; Jul 28th, 2011 at 10:49 AM.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
I just printed the output of the calculations and there are a few problems.
The printing doesn't start until the form is closed and you have some unneeded code so instead of
Code:
Private Sub cmdPrint_Click()
Dim Response As Integer
Response = MsgBox("Ensure Printer is switched on and raedy. Click OK when you are ready", vbInformation + vbOKCancel, App.Title)
If (Response = vbOK) Then
Me.PrintForm
Else
End If
End Sub
You could do
Code:
Private Sub cmdPrint_Click()
If vbokay = MsgBox("Ensure Printer is switched on and ready. Click OK when you are ready", vbInformation + vbOKCancel, App.Title) Then
Me.PrintForm
Printer.EndDoc
End If
End Sub
The above corrects a typo where you had 'ready' typed as 'raedy'.
The EndDoc causes the printing to happen immediately.
There are still 2 problems however:
When you do me.PrintForm the user isn't given the chance to choose the output printer if there are more than one, and the right side of the form is cut off in the output. To solve this I would create a report using Printer.Print and show the label captions and text values etcetera in a formatted fashion.
Last edited by MartinLiss; Jul 28th, 2011 at 11:35 AM.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Hi MartinLiss, you spoke my mind. Point #9:I think two of the text boxes will be taking negative values and setting the range for valid values is way over my head right now. Point #10: That was a big relief cz I was also getting bored seeing those msgs turn up, thanks but is got a problem with the If statement. It gives an error and didn't work with the else statement either. Would love to experiment the 'don't show this message again' option. Could you please help with a clue, thanks? Point #11: I think this point can wait after I hand this thing cz deadline is catching up with me. Point #12 and #14 is like a loop, couldn't get a code and figured a way out in my own terms? Point #13 and #15: has to do with the cost analysis for the life cycle of protecting the pipeline. See reference.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
I will love to experiment with point #4 if both forms won't pose a nuisance on the screen. Point #5: the user is restricted toying with the mother form. What do you think?
. Is giving "False" at the output which I believe the output form does not capture the values during print time. How do I declare the outputs public to be seen by the print command? Thanks for the load of information, my brain is swelled right now.
. Is giving "False" at the output which I believe the output form does not capture the values during print time. How do I declare the outputs public to be seen by the print command? Thanks for the load of information, my brain is swelled right now.
You would need to create Public variables in a code module. My suggestion at this point if you can get away with it is to use PrintForm for now and fix it later.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Thank you MartinLiss, No going back now cz I have edited the whole thing. I'll find a way to figure it out. How much will this app be valued in the market? lol, kidding anyway. Thanks for putting professional touch on my app. Pray that examiner never give me anything less than a distinction else I will mad cz your touch. It looks so pro. Thanks
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Perhaps for future reference, here's a project that allows the user to stop showing a form. You could use it now to show the 'annoying' messages. One thing that's missing is a way for the user to start showing the form again but that could be taken care of with a menu item.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
What you were to pass across those it relate to the below code
Code:
If vbYes = MsgBox("1.Is this the most economical alternative?" & vbCrLf & vbCrLf _
& "2. Prepare Plans and Specification" & vbCrLf & vbCrLf _
& "3. Print Record" & vbCrLf & vbCrLf _
& "4. Exit Program", vbQuestion + vbYesNo, "Confirm") Then
' do something
Else
If vbYes = MsgBox("Select Alternative Cathodic Protection System", vbQuestion + vbYesNo, "Confirm") Then
If (cbocpstype.Text = "Impressed Current") Then
Call ImpressedCurrent
FrameImpressedCurrent.Visible = True
FrameSacrificialCurrent.Visible = False
frmcpcalculatedoutput.frameImpressedCurrentCP.Visible = True
frmcpcalculatedoutput.frmSacrificial.Visible = False
Else
Call SacrificialCurrent
FrameImpressedCurrent.Visible = False
FrameSacrificialCurrent.Visible = True
frmcpcalculatedoutput.lblrecvolt.Visible = False
frmcpcalculatedoutput.lbl21.Visible = False
frmcpcalculatedoutput.lblreceff.Visible = False
frmcpcalculatedoutput.lbl15.Visible = False
frmcpcalculatedoutput.Label9.Visible = False
frmcpcalculatedoutput.Label7.Visible = False
frmcpcalculatedoutput.frameImpressedCurrentCP.Visible = False
frmcpcalculatedoutput.frmSacrificial.Visible = True
End If
End If
End If
I have edited the code a bit and here's what I want the code to do for me but after the second else statement the code is not executed to display the command. Is there a way to go round it?
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
That command should do the loop thing. When I click the msgBox button to say Yes it should display the frame I want on my input button without having to do a click event on the input form, how do I go about that?
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Originally Posted by Ehwenomare
That command should do the loop thing. When I click the msgBox button to say Yes it should display the frame I want on my input button without having to do a click event on the input form, how do I go about that?
We had a similar problem with a combobox and the solution was replacing it with a pair of option buttons. Would that work here?
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
No. I mean at run time. After inputting my values lets say for "Impressed Current" and I click the execute button, now I am not satisfied with the output results and I want to calculate values for the "Sacrificial current" without having to do a click event for the frame of sacrificial to be displayed at run time. I mean displaying automatically when it's not economically visible for me to embark on a project to design my system using Impressed current.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
In the place where you ask if the user is satisfied and he isn't then you can do anything you want with the data input form. If you want to directly execute a Click event of one form from another form via code you would need to change the event from Private to Public and also reference the form. For example
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Thank you MartinLiss, I'm done. That's not gonna happen with this project. I'm deleting that sick code. I think this your code could just solve my printing problem if i declare my execute command as public and i do the calling in the print statement. What do you think?
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Originally Posted by MartinLiss
In the place where you ask if the user is satisfied and he isn't then you can do anything you want with the data input form. If you want to directly execute a Click event of one form from another form via code you would need to change the event from Private to Public and also reference the form. For example
'From Form2
Call Form1.Command1_Click
In the above when I said to make it Public I was referring to the Click event on say offshorecpsystems.
Re: [RESOLVED] Runtime error '91': Object variable or with block not set
Originally Posted by Ehwenomare
In the welcome screen I used a Font size:65 and you said it is too big, what size should I use?
Up to you, but since it is displayed all the time I get tired of seeing the text 'screaming' at me.
Another way around the problem would be to hide the CPSystems form after the user makes a selection and show it again when you unload your other forms.