Good morning,
I have a form that I want to lookup a value in a table and based on whether of not that value is there I want it to run an append query or just show the table.
What I would like
When the button is clicked...check to see if a value is created in a table (using DLookup for that) and then if it isn't there, "run the query" to add the questions and answers ELSE if it is there...show the subforms.
What I have works in pieces but not together.
Thanks!!
Larry
I have a form that I want to lookup a value in a table and based on whether of not that value is there I want it to run an append query or just show the table.
What I would like
When the button is clicked...check to see if a value is created in a table (using DLookup for that) and then if it isn't there, "run the query" to add the questions and answers ELSE if it is there...show the subforms.
What I have works in pieces but not together.
Code:
Private Sub cmdAddQandA_Click()
On Error GoTo Err_cmdAddQandA_Click
'Works great by it self and in with this code on "already existing" values
If DLookup("OccurenceID", "Answers", Me.OccurenceID) Then
Me.qQandAform.Visible = True
Me.qQandAform_Label.Visible = True
Me.sfrmAction.Visible = True
Me.lblActions.Visible = True
Me.qQandAform.SetFocus
Exit Sub
End If
'Works fine when I dont' have the if state below
'The code below will not run the append query if it is a new entry
If (DLookup("OccurenceID", "Answers", Me.OccurenceID)) <> Me.OccurenceID Then
'Runs an append query to make the question and answer fields
DoCmd.SetWarnings False
Dim stDocName As String
stDocName = "qQandA"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Me.qQandAform.Visible = True
Me.qQandAform_Label.Visible = True
Me.qQandAform.SetFocus
Me.cmdAddQandA.Visible = False
Me.Refresh
DoCmd.SetWarnings True
End If
Exit_cmdAddQandA_Click:
Exit Sub
Err_cmdAddQandA_Click:
MsgBox Err.Description
Resume Exit_cmdAddQandA_Click
End Sub
Thanks!!
Larry