Access: How to clear ALL fields on form load

ChiknHead

Senior member
Jul 7, 2001
646
0
0
I have a form based on a query, it loads all the fields with data from last record.
How can you have these fileds clear when the form load?
Also how do you "compile" this database into an exe, so that it can be run on a machine without access.

Thanks
 

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
function clearform(cancel as integer)
Dim Clear
Me.fieldname1 = clear
Me.fieldname2 = clear
Me.fieldname3 = clear
'and so on
end function

If the fields are all named numericly, you could just increment it like this. This is assuming the fields are named numbericly (with a number at the end) you pass in the number of fileds that are in the record.

Private Sub Form_Load()
call clearform(20) 'this assumes there are 20 fields
end sub

Function Clearform(FormFields as Integer) ' limit of 30k fields. if more than 30k use "formfields as long"
Dim clear
Dim Fieldname as string
Do until formfields = 0
   fieldname = "ThisIstheNameoftheFieldonTheForm" & formfilelds
   me.fieldname = clear
   formfields = formfields-1
Loop
EndFunction
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,000
126
Or you can simply set the default value in each field's properties to be null.

Also how do you "compile" this database into an exe, so that it can be run on a machine without access.
You can't.

However if you have the developer version of Microsoft Office then you can use it to install the Access runtime libraries onto each machine and then you can run it without having Access installed.
 

jaybittle

Senior member
Jan 23, 2001
550
0
0
Originally posted by: ChiknHead
How can you have these fileds clear when the form load?

Here's some VB6 code that I use to clear out a form.. not sure if it will work in Access - never tried it..

For Each vControl In Me.Controls
If TypeOf vControl Is TextBox Then
vControl.Text = ""
End IF
Next vControl


cheers,
--jb