Dialog not writing records correctly

G

Guest

I have a sub form with a command button that invokes a dialog.

When there are matching records (QuestionID) in the table the dialog is
populated correctly but, any records that are added to the dialog are written
to the table with QuestionID of 0 (zero) instead of the current QuestionID.

The code for the on click event is
Dim sWhere As String

Me![fiQuestionLvl3].SetFocus
sWhere = "[QuestionID] = " & Str(QuestionID)
'MsgBox "1 | " & sWhere
DoCmd.OpenForm "fSrvResponseList", , , sWhere, , A_DIALOG, Str(QuestionID)

Any ideas please.
 
G

Guest

The WhereCondition will work only on existing records, to populate new
records use the OpenArgs parameter you are sending.

DoCmd.OpenForm "fSrvResponseList", , , sWhere, , A_DIALOG, QuestionID


On the OnLoad evet of the fSrvResponseList form, write the code

If Me.NewRecord And Not IsNull(Me.OpenArgs) Then
Me.[QuestionID] = Me.OpenArgs
End If
 
G

Guest

Thanks for that Ofer
--
Graham


Ofer Cohen said:
The WhereCondition will work only on existing records, to populate new
records use the OpenArgs parameter you are sending.

DoCmd.OpenForm "fSrvResponseList", , , sWhere, , A_DIALOG, QuestionID


On the OnLoad evet of the fSrvResponseList form, write the code

If Me.NewRecord And Not IsNull(Me.OpenArgs) Then
Me.[QuestionID] = Me.OpenArgs
End If


--
Good Luck
BS"D


Graham said:
I have a sub form with a command button that invokes a dialog.

When there are matching records (QuestionID) in the table the dialog is
populated correctly but, any records that are added to the dialog are written
to the table with QuestionID of 0 (zero) instead of the current QuestionID.

The code for the on click event is
Dim sWhere As String

Me![fiQuestionLvl3].SetFocus
sWhere = "[QuestionID] = " & Str(QuestionID)
'MsgBox "1 | " & sWhere
DoCmd.OpenForm "fSrvResponseList", , , sWhere, , A_DIALOG, Str(QuestionID)

Any ideas please.
 

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