Add record subform problem

G

Guest

When I click the 'add record' button on the navigation toolbar, a blank
record appears in the fields of my main form, but the text boxes to enter
data into my subforms disappear making impossible to enter data into the
subforms. What is causing this?
 
V

Vinayak N

Hi,

Try entering some data into the main form fields and then see if you
get the text boxes available in the sub-form for entering data.

I know the step that I have told is very elementary but still let me
know if you have already tried it and also then explain your problem a
bit more in detail later.

Regards,
Vinayak
 
G

Guest

No that didn't work. I think I found where the problem is, but still do not
know how to fix it. I wanted users to decide whether they wanted to add a
new record or edit an existing record. Instead of the navigation toolbar, I
inserted a "Add Record" command button. In the main form properties, I set
the AllowAddition Property to 'No' and in the 'On Click' code for the command
button, I inserted the following code:
Me.AllowAdditions = True

This works great with the main form, but does not allow new records to be
added to the subforms. When I removed the command button and put the
navigation toolbar back in and set the main form 'AllowAddition' Property
back to Yes, the subform still would not allow new entries.

I guess my question is now. Is it possible to use a not allow additions
unless an add record is clicked and still be able to add data to the
subforms? If so, what code am I leaving out? Also, will I have the same
problem when I create an edit button and change allowedit property to false?

Thank you for your help.
 
J

JK

If your subForm is linked to the main form on a key other than the form key,
that filed is Null, until you put a value in it.
Thus the subForm has nothing to link to.


Is that the case?

Regards/JK
 
J

JK

Normally and the best way to do it, though not mandatory, is like this:

tbl (FrmMain Souce)
------

fldMain_ID (key)
Field
Field
Filed
etc.

tblDetail (SubForm Source)
-----
fldDetails_ID (key)
FldMain_ID (long, Foreign Key)
Field
Field
Field
Field
etc.

Link tblMain with tblDetail on the Main_ID as one-to-many relationship

In your *SubForm* properties you set *both*" Link Child Field" and "Link
Master Field" to "fldMain_ID" (no quotations marks)

if you still have problems, it will be easier to help you if you post here
your actual tables structures (just the relevant fields), realtinship, if
any and what you have now as Master and Child links.

Regards/JK
 
G

Guest

Ok. Now I understand. The phrase form key through me off. Here is my table
structure:

tblBulletin (frmBulletin main source)
---------------------------------------
BulletinID (Autonumber, Primary Key)
State
Bulletin Number
Date Issued
Date Effective
Title
Summary
Analyst

tblBill (main source for subfrmBill)
--------------------------------------
BulletinID (Long, Foreign Key, Combined with BillNumber - Primary Key)
BillNumber (Text, Combined with BulletID - Primary Key)

tblBulletinLOB (main source for subfrmLOB)
-------------------------------------------------
BulletinID (Long, Foreign Key, Combined with BulletinLOB - Primary Key)
BulletinLOB (Text, Combined with BulletinID - Primary Key)

tblCategory
---------------
BulletinID (Long, Foreign Key, Combined with BulletinCategory - Primary Key)
BulletinCategory (Text, Combined with BulletinID - Primary Key)

Tables tblCategory, tblBulletinLOB, and tblBill all have one-to-many
relationships with tblBulletin. In each subform, the Link Master Field
Property is set to BulletinID (tblBulletin) and the Link Child Property is
set to BulletinID.

I think that is about all the relevant information pertaining the problem.
Let me know if you have any suggestions.

Thank you.
 
J

JK

Hmmm, Your structure is ok - I must be some thing else

In order to look for the problem, go to your property sheets of *both* forms
and change or ensure that *both* Allow Edits and Allow Additions are turned
on

Lets start from the obvious

A trap I occasionally fall into is to forget to make the subform a
continuous form. if you fell into the same trap in your sub form you will
see only one record, if there are any, or if there are no records you will
see only the new record. IIf you fell into the same trap, correct it.

Now, create a command button that do nothing (if your wizard is turned on
press cancel, in the wizard after you have drawn the button.

1. Open the property sheet for the button name and name it, Lets call it
"AddButton" (No quotations marks). Put in the caption or image, as you wish

2. Now, there are two possibilities:

a) Once the user click on "AddButton", he can add records regardless of
which record he/she will be in subsequently

Private Sub AddButton_Click()

Dim strSubForm As String

strSubForm = "YourSubForm"

Me.Form.AllowAdditions = True
Form(strSubForm).Form.AllowAdditions = True
'Note: both "Form" in singular

DoCmd>GoToControl "Your first field on the main form"


End Sub


b) The user has to click the "AddButton" every time he/she wants to add a
record.

Still use the Click event as above but add to the On Current Event Sub
( or Create one)

Dim strSubForm As String

strSubForm = "YourSubForm"

If Me.Form.NewRecord Then
Form(strSubForm).Form.AllowAdditions = True
Else
Me.Form.AllowAdditions = False
Form(strSubForm).Form.AllowAdditions = False
End If

+++++++
Advise: Always keep the AllowEdits turned on, if it is turned off you cannot
click buttons or use the scroll bars. you can disable (or lock) the fields
you want protected, if need be. If you disable a field *and* lock it you
will maintain the colour (i.e. it will not grey out).

My apology if I taught grandma how to sack eggs, Let me know how you go.

Regards/JK
 

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