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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update fields in OnUnload event

Status
Not open for further replies.

xezekielx

IS-IT--Management
Jun 30, 2005
93
CA
Hi everyone! Here's what I'm trying to do: when a subform loads, I want to put the data of every field in a array. When the subform closes, the fields' data is restored from the array. The trick is that if the user pressed the 'Save' button located on the MAIN FORM, the array will be updated with the fields' new data so that when the form closes, the data 'restored' in the fields from the array will be the same. First, is it possible to do this? Second, is there any way to update the fields' value in the OnUnload event? Any help would be much appreciated!
 
Hallo,

How many fields are we talking about. If there's only a few you could do it manually:
Code:
public const gcintField1 as Integer = 1
public const gcintField2 as Integer = 2
public const gcintField3 as Integer = 3

Dim gstrDataCopy (gcintField1 to gcintField3) as string

Then in your Form Unload or Close or whatever, you'll have to experiment to see which is best:
With Me
  gstrDataCopy (gcintField1)= !txtField1
  gstrDataCopy (gcintField2)= !txtField2
  gstrDataCopy (gcintField3)= !txtField3
End With

Or you could use a loop:
Code:
public const gcintNoOfFields as Integer = 50
public const gcintFieldName as integer=0
public const gcintFieldValue as iinteger=1

Dim gstrDataCopy (1 to gcintNoOfFields,0 to 1) as string

Then in your Form Unload or Close or whatever, you'll have to experiment to see which is best:
Dim ctlControl as Control
Dim intPtr as integer
intPtr =1
For Each ctlControl in Me.Controls
  With ctlControls
    if .type=vbTextBox then
      if nz(.ControlSource,"")<>"" then
        gstrDataCopy (intPtr, gcintFieldName)= .Name
        gstrDataCopy (intPtr, gcintFieldValue)= nz(.Value,"")
        intPtr=intPtr+1
      endif
    endif
  End With
next ctlControl

Summat like that. You can make it a lot more fancy if you need to, but that's the basics,

- Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top