Transfering Data from one form to another form

first form is a sales invoice, second form is hopefully going to be th

Page 1 of 1

5 Replies - 2753 Views - Last Post: 06 December 2009 - 02:47 PM Rate Topic: -----

#1 RoeDoran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-December 09

Transfering Data from one form to another form

Post icon  Posted 06 December 2009 - 12:29 PM

Hello

The first form in my project is a simple form for a shop selling cars. At the end of the form is a text box called txtTotal.text, this is the total cost of each sale. When I press the print button I not only want to print a sales invoice(I have that bit done) but I also want the total in txtTotal.text to be added to lblDaysTakings on my second form called frmAudit.
Ive searched the web far and wide and cant find anything either suitable or within my level of understanding.

Ive tried code such as
Private Sub cmdPrint_Click()

  Dim curTotal As Currency
  Dim curDaysTakings As Currency
  Dim frmAudit As Form
  Dim frmCarSales As Form
  
  
  
  curTotal = Val(txtTotal.Text)
  curDaysTakings = Val(lblDaysTakings)

curDaysTakings = curDaysTakings + curTotal

'or

frmAudit.DaysTakings = frmAudit.DaysTakings + frmCarSales.Total



and several other combinations but Im obviously a mile and a half off track as Im not getting anywhere, can anybody offer me any advice? Id really appreciate any help at all, thanks.

The project is a lot bigger than just the print button but I didnt see the point in posting the rest as I have everything else sorted out, its just transfering the numbers from one form to the other thats getting me.
Thanks again in advance

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code: Thanks, PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Transfering Data from one form to another form

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Transfering Data from one form to another form

Posted 06 December 2009 - 12:48 PM

You shouldn't have the Form Dims in this method the Form names exist in the Global name space and you are HIDING them by creating local variable names of the same.
You want FormName.ControlName.Text for accessing the control on a different form.
frmAudit.lblDaysTakings.Text = CDec(frmAudit.lblDaysTakings.Text) + curTotal 


You shouldn't have the Form Dims in this method the Form names exist in the Global name space and you are HIDING them by creating local variable names of the same.
Was This Post Helpful? 0
  • +
  • -

#3 RoeDoran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-December 09

Re: Transfering Data from one form to another form

Posted 06 December 2009 - 12:55 PM

View Postmark.bottomley, on 6 Dec, 2009 - 11:48 AM, said:

You shouldn't have the Form Dims in this method the Form names exist in the Global name space and you are HIDING them by creating local variable names of the same.
You want FormName.ControlName.Text for accessing the control on a different form.
frmAudit.lblDaysTakings.Text = CDec(frmAudit.lblDaysTakings.Text) + curTotal 


You shouldn't have the Form Dims in this method the Form names exist in the Global name space and you are HIDING them by creating local variable names of the same.

Thanks for offering your help you have no idea how much i appreciate it. I did as you said I deleted the forms Dims and inserted the line of code you wrote out but I got an error message "Method or Data Member not found" when I went back to the code editor it had the TEXT in (frmAudit.lblDaysTakings.Text) highlighted. I figured this was because its a label and not a text box so I deleted the word TEXT but it still didnt work.
Was This Post Helpful? 0
  • +
  • -

#4 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Transfering Data from one form to another form

Posted 06 December 2009 - 12:59 PM

You haven't shown enough code - I'm guessing at what you called the other forms and their controls. Use the VB code completion to get the correct one. You do need the .Text extension to access the Text property of whatever control is on the form. There may also be a problem in that you haven't loaded the form so it is not visible. You may have the form hidden, but it most be loaded.
Was This Post Helpful? 0
  • +
  • -

#5 RoeDoran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-December 09

Re: Transfering Data from one form to another form

Posted 06 December 2009 - 01:08 PM

View Postmark.bottomley, on 6 Dec, 2009 - 11:59 AM, said:

You haven't shown enough code - I'm guessing at what you called the other forms and their controls. Use the VB code completion to get the correct one. You do need the .Text extension to access the Text property of whatever control is on the form. There may also be a problem in that you haven't loaded the form so it is not visible. You may have the form hidden, but it most be loaded.

YESSSS I got it, I cant believe it finally. It was your code basically with a tiny little change to it
 frmAudit.lblDaysTakings = frmAudit.lblDaysTakings + frmCarSales.txtTotal.Text

Thanks a lot man seriously, Ive been trying all night to figure that out. I owe you a pint and a packet of smarties.
Thanks again
Was This Post Helpful? 0
  • +
  • -

#6 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Transfering Data from one form to another form

Posted 06 December 2009 - 02:47 PM

Eat the Smarties (red ones last), drink the pint and click the "This Post Was Helpful" link below!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1