Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing data in a variable and text box 1

Status
Not open for further replies.

hawaiian1975

Programmer
Nov 7, 2003
26
US
Ok, there are several sections for this problem. First I am using a module for my global variables because I need the data stored on one form to integrate into another form.

This is what I have for my global variables:

Option Explicit
Public wheel1 As String, wheel2 As String, wheel3 As String, wheel4 As String
Public wheel5 As String, wheel6 As String, wheel7 As String, wheel8 As String

Second part is that on my Data Entry Form I added a clear menu click to clear up the data in the text boxes and the data stored in the variables: Here is that code:

Private Sub mnuDataClear_Click()
wheel1 = ""
wheel2 = ""
wheel3 = ""
wheel4 = ""
wheel5 = ""
wheel6 = ""
wheel7 = ""
wheel8 = ""

Dim intCount As Integer
For intCount = 0 To 7
txtWheel(intCount).Text = ""
Next intCount

End Sub

Also here is the code when I change to the next form:
Private Sub mnuDataNextForm_Click()
wheel1 = txtWheel(0).Text
wheel2 = txtWheel(1).Text
wheel3 = txtWheel(2).Text
wheel4 = txtWheel(3).Text
wheel5 = txtWheel(4).Text
wheel6 = txtWheel(5).Text
wheel7 = txtWheel(6).Text
wheel8 = txtWheel(7).Text

'hide and show the forms
frmCompute.Show
frmDataEntry.Hide
End Sub

Okay, once I get to the Compute Form I have the data from the Data Entry Form added and shown in some text boxes.

Private Sub Form_Load()
'load data from Data Entry Form
txtAxle(0).Text = Val(wheel1) + Val(wheel2)
txtAxle(1).Text = Val(wheel3) + Val(wheel4)
txtAxle(2).Text = Val(wheel5) + Val(wheel6)
txtAxle(3).Text = Val(wheel7) + Val(wheel8)
End Sub

Ok, on this form I also have a clear button. When I click it and go back to the Data Entry form to enter new data, it does not show up on the Compute Form when I revert back.

Private Sub cmdClear_Click()
Dim intCount As Integer
For intCount = 0 To 3
txtAxle(intCount).Text = ""
Next intCount

wheel1 = ""
wheel2 = ""
wheel3 = ""
wheel4 = ""
wheel5 = ""
wheel6 = ""
wheel7 = ""
wheel8 = ""
End Sub


 
Probably because you use the Form_Load event to display the data in the textbox's, then you hide the form, later you reshow the form but not reload it, so the data is not shown.

Also,
Declare the variables like so...
Public wheel1 As String
Public wheel2 As String
Public wheel3 As String
etc etc
 
>Also here is the code when I change to the next form:

Private Sub mnuDataNextForm_Click()
wheel1 = txtWheel(0).Text
wheel2 = txtWheel(1).Text
wheel3 = txtWheel(2).Text
wheel4 = txtWheel(3).Text
wheel5 = txtWheel(4).Text
wheel6 = txtWheel(5).Text
wheel7 = txtWheel(6).Text
wheel8 = txtWheel(7).Text

'hide and show the forms
With frmCompute
'load data from Data Entry Form
.txtAxle(0).Text = Val(wheel1) + Val(wheel2)
.txtAxle(1).Text = Val(wheel3) + Val(wheel4)
.txtAxle(2).Text = Val(wheel5) + Val(wheel6)
.txtAxle(3).Text = Val(wheel7) + Val(wheel8)
.Show
End With
frmDataEntry.Hide
End Sub

>Okay, once I get to the Compute Form I have the data from the Data Entry Form added and shown in some text boxes.

Private Sub Form_Load()
'Do nothing
End Sub
 
Instead of declaring 8 variables as strings, you might like to try calling 1 variable as an array of 8 strings. This way you can iterate through the variables using for / next loops, and not have to write separate code for each value.

eg dim wheel(7) as string. (arrays start at base 0 unless you specify otherwise.)

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top