How to initialize field on the tab control

K

Kamy_s

I have a form, and the form have a tab control with two pages.
the page has few fields (drop down list, date field and a text) fro
one of the table.

I would like to initialize those fields when the form is open.

form (form1)
tab control (tab_control)
Pages (Page1 and Page2)
Page1 fields (field1)
Page2 fields (field2 and field3)

How I can do that ? In which event Form_Open or Form_Current and how ?

Tried the below code

Private Sub Form_Current()
'Initiliaze variables on the form.
form1.field1.Value = ""
form1.field2.Value = ""
form1.field3.Value = ""
End Sub

Please advise.

Thanks in advance
 
G

Gary Miller

Try the following...

Private Sub Form_Current()
'Initiliaze variables on the form.
Me!field1 = ""
Me!field2 = ""
Me!field3 = ""
End Sub

Do be aware that if you're OnCurrent fires on an existing
record, you will be deleting what was stored on that record.
--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
D

Dan Artuso

Hi,

Me.field1.Value = ""
Me.field2.Value = ""
Me.field3.Value = ""

in the Load event of the form
 
K

Kamy_s

I am using the below code and got error message

Runtime error 2448
You can't assign value to this object

Private Sub Form_Load()
Me.field1.Value = ""
Me.field2.Value = ""
Me.field3.Value = ""
End Sub

The fields are on the tabcontrol page1 and not on the form, makes an
difference. ?

Please advise.

Thanks
 
G

Gary Miller

No, it doesn't make a difference that the controls are on a
Tab Page, you still refer to them by name.

It sounds like one of your controls does not like having a
value set to it, or at least not that value. If you put a
breakpoint in the code ( click on the bar to the left of
your first line and a round circle should appear ) you
should find out which control(s) is creating the error.

You could also try setting the controls to Null instead of
"". A listbox with 'LimitToList' would probably not like ""
which is not in the list.

Me.field1.Value = Null

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
K

Kamy_s

I have tried all the different combination in both the event and nothing
is working

Private Sub Form_Current()
Me!field1 = ""
End Sub

Private Sub Form_Load()
Me!field1 = ""
End Sub

Private Sub Form_Current()
Me!field1.value = ""
End Sub

Private Sub Form_Load()
Me!field1.value = ""
End Sub

Private Sub Form_Current()
Me.field1.value = ""
End Sub

Private Sub Form_Load()
Me.field1.value = ""
End Sub

Please advise.

Thanks
 
K

Kamy_s

The fields on the tabcontrol page are database fields and not the
unbound fields. Does this matters. ?
 
K

Kamy_s

(1) The field which is on the form itself is working fine. Can assign
value.

(2) The problem is with the fields on the page of tab, I am unable t
assign the value of "" or Null.

(3) I have created a unbound field on the page of the tab and was abl
to assign the value through Form_Current() event.

So now I can see some difference between the database field and th
text field.

Please advise
 
G

Gary Miller

If they are database fields, I am very curious why you are
trying to do this as they probably have data in them for
each record and you will wipe that out every time you change
records with the OnCurrent and you will wipe the data from
the first record shown with the OnLoad. Are you trying to
clear them so you can enter a new record? This would not be
the way to do it then, as if you go to a new record, they
will inheritly be blank and the method you are trying to use
will wipe out an existing record instead of creating a new
one.

If I am off base with the above, I would next make sure that
the controls are Enabled and not 'Locked'. Did you try
stepping through the code as I suggested? What did you find
there?

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
K

Kamy_s

First of all thank you sir (Gary Miller) for taking deep interest in m
problem.

(1)
I have found the difference as the database fields are having Contro
Source= table name and the text field which I have created on the ta
control is without any Control Source.

I am able to initialize the text field but not the database field.

I am creating a Query Screen, So depending on the value entered on th
search field on the main form and clicking the search button wil
retrieve the data on the tab pages.

When I open the form the tab pages have default values "#Name?"

So I want to initialize the fields with empty string or null in th
form_current event.


(2)
After retrieving the data on the tab the fields are not enable. Thoug
the field property is enable.

Thank
 
G

Gary Miller

Well, from the latest that you sent I can see a problem. The
database controls ControlSource should not be the name of
the table. They should be set to be the name of a field in
the table.

Are these controls on a subform that is on the tab page or
are they supposed to pull their data from the same table as
the main part of the form which you say is working? If they
are on a subform...

1) make sure that the subform itself has it's RecordSource
properly set.

2) make sure that the Master/Child relationships are
properly set on the subform control that holds the subform.

3) If the above are correct, you should be able to click on
the right side of the ControlSource of your controls and
have a list of the fields available in the recordset of the
subform or form. If not, there is still a problem with the
above items.

The '#Name' error means that Access doesn't understand the
ControlSource it was assigned. If everything is setup
properly, you shouldn't need to do what you were trying to
do in assigning them a "" value.

You are welcome for the help.

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
K

Kamy_s

The database controls ControlSource is the field name and not the tabl
name. (In my previous thread I was wrong it should be field name)

Now I have found the solution.

(1) I am not assigining the ControlSource initially.
(2) In the Form_Load event I am initializing fields with "" which i
working fine.
(3) Before doing .RecordSource = mstrSQL I am assigining th
ControlSource to each fields (Field Name).
(4) I am able to retrieve data depending on the search criteria fro
multiple tables.

!!!!!New Problem!!!!!
(5) The data retrieved cannot be updatable, When I try to modify th
data from the form/tabcontrol/tab page gives message "Record set is no
updatable".

Any help is appreciated
 
G

Gary Miller

Why do I have the feeling that the method you are using is
making this much harder for you than it should be. Why do
you feel it is neccessary to initialize the ControlSource of
every control on the OnLoad event with "" which is basically
nothing. That is probably what it would be if you did
nothing. Do these controls need to change their
controlsource every time you open the form for some reason I
don't understand? Why not just assign them their
controlsource once in design view and be done with it? Maybe
if you gave me a little bigger picture of what you are
trying to do and why, I could offer some more educated
advice.

On your new problem, I really have no way to help you if you
don't include the SQL that is giving you the problem in the
RecordSource. Obviously, this SQL is the problem if the
recordset is not updateable.

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
K

ket_shah

But now I have got the solution.

Query based on three or more tables in which there is
many-to-one-to-many relationship. I could not modify the data on th
form.

Modified the code as below

.RecordSource = mstrSQL
Const Dynaset = 1
Forms!FormName.RecordsetType = Dynaset

OR

Can change the form data property RecordsetType from 0 to 1

And was able to modify the data after retreving through the searc
button on the form.

Thank you Sir for everything. Now I am moving smoothyl (till I com
across another tuff problem).

(ket_shah and kamy_s both are my accounts)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top