If Statement Help

lcook1974

Registered User.
Local time
Today, 17:31
Joined
Dec 21, 2007
Messages
330
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.

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
 
Your dlookup statement is incorrectly formed. Here is the basic structure from Access Help.
Code:
 DLookup("[LastName]", "Employees", "[EmployeeID] = 1")
Look it up in Access help, as it gets a bit complicated. Especially if your data is text versus numeric.
 
AWESOME!!! Thank you!

Larry
 

Users who are viewing this thread

Back
Top Bottom