If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
bound subform: filling a new redord
Hello. I have a problem with bound subform.
I have a MAIN table with following fields: [id] (int - identity - not null - primary key), [title] (nvarchar) ... and the SUB table with [sid] (int - identity - not null - primary key), [mid] (int - not null), [desc] (nvarchar), ... I created form MAINFRM based on MAIN recordset and subform based on SUB records. They are linked via [id]=[mid]. If user creates new record by MAINFRM, types [title] then fills [desc]s - all works fine. But if in a new MAINFRM's record user try to fill [desc] as a first step, the error message appears (about setting non-variant field to Null). I undersnad that new record have no [id] (i.e. =Null) and Access tries to set [mid] to Null, so it fails. But HOW TO GET ROUND THIS? |
#2
|
|||
|
|||
bound subform: filling a new redord - note
Note: It's ADP (SQL Server)
|
#3
|
|||
|
|||
bound subform: filling a new redord
Cancel the BeforeInsert event of the subform, if the main form is at a new
record: Private Sub Form_BeforeInsert(Cancel As Integer) If Me.Parent.NewRecord Then Cancel = True MsgBox "Fill in the main form first." End If End Sub -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Raider" wrote in message ... Hello. I have a problem with bound subform. I have a MAIN table with following fields: [id] (int - identity - not null - primary key), [title] (nvarchar) ... and the SUB table with [sid] (int - identity - not null - primary key), [mid] (int - not null), [desc] (nvarchar), ... I created form MAINFRM based on MAIN recordset and subform based on SUB records. They are linked via [id]=[mid]. If user creates new record by MAINFRM, types [title] then fills [desc]s - all works fine. But if in a new MAINFRM's record user try to fill [desc] as a first step, the error message appears (about setting non-variant field to Null). I undersnad that new record have no [id] (i.e. =Null) and Access tries to set [mid] to Null, so it fails. But HOW TO GET ROUND THIS? |
#4
|
|||
|
|||
bound subform: filling a new redord
Thanks!
But how can I give users an ability to fill subform first? Private Sub Form_BeforeInsert(Cancel As Integer) ' try to create main record If Me.Parent.NewRecord Then Me.Parent![title] = null End Sub gives [mid]=1 :-( Cancel the BeforeInsert event of the subform, if the main form is at a new record: Private Sub Form_BeforeInsert(Cancel As Integer) If Me.Parent.NewRecord Then Cancel = True MsgBox "Fill in the main form first." End If End Sub |
#5
|
|||
|
|||
bound subform: filling a new redord
You can't.
Assuming a one-to-many relation between the main form's table and the subform's table, you have to enter the main form record before you can create the related records in the subform. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Raider" wrote in message ... Thanks! But how can I give users an ability to fill subform first? Private Sub Form_BeforeInsert(Cancel As Integer) ' try to create main record If Me.Parent.NewRecord Then Me.Parent![title] = null End Sub gives [mid]=1 :-( Cancel the BeforeInsert event of the subform, if the main form is at a new record: Private Sub Form_BeforeInsert(Cancel As Integer) If Me.Parent.NewRecord Then Cancel = True MsgBox "Fill in the main form first." End If End Sub |
#6
|
|||
|
|||
bound subform: filling a new redord
Okey, I'm unable to create subform's record without having record in the
main form. And the possible solution is to auto-create record in the main form then trying to create a subform record. But how to implement it? "Allen Browne" сообщил/сообщила в новостях следующее: ... You can't. Assuming a one-to-many relation between the main form's table and the subform's table, you have to enter the main form record before you can create the related records in the subform. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Raider" wrote in message ... Thanks! But how can I give users an ability to fill subform first? Private Sub Form_BeforeInsert(Cancel As Integer) ' try to create main record If Me.Parent.NewRecord Then Me.Parent![title] = null End Sub gives [mid]=1 :-( Cancel the BeforeInsert event of the subform, if the main form is at a new record: Private Sub Form_BeforeInsert(Cancel As Integer) If Me.Parent.NewRecord Then Cancel = True MsgBox "Fill in the main form first." End If End Sub |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help with cascading combos | Tom | Using Forms | 19 | July 1st, 2004 11:11 PM |
Recordset in subform based on field in parent form | Lyn | General Discussion | 15 | June 14th, 2004 03:10 PM |
Record Source for SubForm | David F | Using Forms | 1 | June 7th, 2004 10:42 PM |
subform within subform | Chris | Using Forms | 1 | June 4th, 2004 10:26 PM |