Making A Budget Form

Posted on 2006-07-15
Last Modified: 2010-04-30
Here we go,

I am trying to make a form with a budget on it.  I am trying to make it with a estimated side and an actual side.  Then I want to be able to save it as a disk file and print it to my printer.  What I am using for code somewhat does what I want for the budget but I need better.  Here is my code.

Under the Estimated side, I placed the three (3) text boxes on top of each other and removed the Text property from each and then did the same with the actual side using text boxes 4-6.  I then placed a label box under each column respectively called label1 and label2 and finally placed a command button centered underneath the two columns.  Here is the code finally I am using:

Private Sub Command1_Click()
   Dim int FirstNumber As Integer
   Dim int SecondNumber As Integer
   Dim int ThirdNumber As Integer
   Dim int FourthNumber As Integer
   Dim int FifthNumber As Integer
   Dim int SixthNumber As Integer
   intFirstNumber = val(Text1.Text)
   intSecondNumber = val(Text2.Text)
   intThirdNumber = val(Text3.Text)
   intFourthNumber = val(Text4.Text)
   intFifthNumber = val(Text5.Text)
   intSixthNumber = val(Text6.Text)
   Label1.Caption = intFirstNumber + intSecondNumber + intThirdNumber
   Label1.Caption = intFourthNumber + intFifthNumber + intSixthNumber
End Sub

I know how to print object text but that is it.

Please, I neeed help!!!
Question by:lpetrowicz
  • 4
  • 2
LVL 20

Expert Comment

ID: 17115689
First change
   Label1.Caption = intFourthNumber + intFifthNumber + intSixthNumber
   Label2.Caption = intFourthNumber + intFifthNumber + intSixthNumber
unless you want to be overwriting you first label by accident.

There are two ways to compile the data for printing. What I would do is create a new textbox and simply add everything to it.

Dim Output as String
Output =  Text1.text & vbNewLine & Text2.text & vbNewline & Text3.text & _
                vbNewline & "Total: " & Label1.caption & vbNewLine & vbNewline & _
                Text4.text & vbNewLine & Text5.text & vbNewline & Text6.text & _
                vbNewline & "Total: " & Label2.caption

You can organize the data however you want.

Then call up a PrintDialog, if you need help with that let me know, and then to save it you can just output the string to a file and save that.
This will teach you how to use a simple print dialog box.  or
And to write a file (very simple) try this:

Let me know if you encounter and specific error in doing this.


LVL 20

Expert Comment

ID: 17115694
Oh I almost forgot. The other thing you can do to compile your data is to automatically take a screenshot of the form and then automatically print a picture of the screenshot, but I think that will look a little rough.

Author Comment

ID: 17115766
how would you do a screenshot within the program?
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

LVL 20

Expert Comment

ID: 17115808 or
for sample code if you're in a hurry.

I explained it really well in another topic, I'll try to find that.
LVL 20

Accepted Solution

alainbryden earned 500 total points
ID: 17115827
allright this is what I said:

IF you want to display it, then just loop through each of the form contents with a msgbox, but I'm sure this isn't what you wanted to do or you wouldn't have asked.

IF by print form you mean to use an actual printer, than you need to import the common dialogue box in your components. This is very simple to do, and then you just create a new common dialogue, set the type as PrintDialoge, and then you're off.

If all you want to do is to take a snapshot of a form, like a screenshot type thing, then you need to simulate the pressing of Alt+PrintScreen on the keyboard.  To do this you do the following:

Declare Function keybd_event Lib "user32" Alias "keybd_event" _
     (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
     ByVal dwExtraInfo As Long) As Long

so that you can do a keyboard event. THen when you want the screenshot:

keybd_event(VK_Alt, 0, 0, 0) 'send a key
keybd_event(VK_PrintScreen, 0, 0)
keybd_event(VK_Alt, 0, KEYEVENTF_KEYUP, 0) 'release key

Then to store it something like:

frmcontrols.snapImage1.Picture = Clipboard.GetData(vbCFBitmap)

This is where I said it:

The guy wanted to do pretty much the same thing as you, print the contents of his form, so take a look at what I wrote there and it will likely solve all your problems. I also show how to properly use the print dialog box

Author Comment

ID: 17115936
I will try it all throughout the evening and let you know how it goes.  Thanks.

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now