"Kaur" <ka***@saic.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Thanks for such a quick response. I updated the code. Now I am getting
the error: Searching records using the list box can not find the form
frmQuestion referred to in a macro expression or visual basic code."
May be I did not give enough details of the forms.
Form 1 is a search form to search for all the surveys in db. It has an
unbound list box that displays all the surveys. Clicking on one of the
surveys opens up 2nd form.
This form "frmQuestions" has all the questions related to the survey.
This form has an unbound list box that displays all the relevant
questions. Underneath the list box is Question text in combo box,
question no as it appers in the survey (a text box). This form has a
subForm that displays the subquestions associated with each Question.
The form "frmQuestion" has a cmd button which opens the Form3
"frmAddQuestions".
This form gets the survey key from tblSurvey and has a subform called
sfrmAddQuestions where users does the data entry for a question. I
created this type of form so that I can still add the question for the
relevant Survey.From here users choose the questions from a combo box and if the
question is not in the combo box then it allows the users to add the
question. This form has cmdSaveRecord cmd button where I added the
code and still getting the error.
Any help would be appreciated.
My head is starting to ache with all that! I re-read twice and still don't
quite get it. Perhaps someone else can step in, but in any case, use the
bulk of my code with the structure and error handling. You could also use
the following function to check whether you have the expected form open,
before you call Forms!MyForm ... blah,blah,blah
Public Function IsFormLoaded(strName As String)
IsFormLoaded = (SysCmd(acSysCmdGetObjectState, acForm, strName) <> 0)
End Function
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_Handler
Dim strFind As String
Dim lngQID As Long
' Save this record if it needs it
If Me.Dirty = True Then
Me.Dirty = False
End If
' Get the current QuestionID
lngQID = Nz(Me!QuestionID, 0)
' Check we have a valid ID
If lngQID > 0 Then
DoCmd.Close acForm, Me.Name
Else
Exit Sub
End If
MsgBox "Question ID=" & Cstr(lngQID) & _
vbCrLf & "Now what?"
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub