If statement won't run

paulcraigdainty

Registered User.
Local time
Today, 13:18
Joined
Sep 25, 2004
Messages
74
I have the following code below which works perfectly. I am trying to add a series of IF statements to the end of it. However, when i execute the code I get an error. Does anyone know why? I know the IF statement works as I can execute it behind a command button


Private Sub TicketRef_Click()
Dim rst As DAO.Recordset

DoCmd.OpenForm "frmFeedback"

Set rst = Forms!frmfeedback.Recordset.Clone

rst.FindFirst "[id] =" & Me.ID

Forms!frmfeedback.Bookmark = rst.Bookmark

Application.SetOption "Confirm action queries", 0
Application.SetOption "Confirm document deletions", 0
Application.SetOption "confirm record changes", 0

Form.Requery
 
are you sure this is working

rst.FindFirst "[id] =" & Me.ID

i think you may need a space after the = sign

--------
what error are you getting, and where are you tring to put the code
 
Hi,

Yes the code shown is working. The problem i have is when i add a series of IF statements to the end of it. Ideally the code below is what I want to run. When i try to execute i receive the following error: "Run time error 424 - object required"


Private Sub TicketRef_Click()
Dim rst As DAO.Recordset

DoCmd.OpenForm "frmFeedback"

Set rst = Forms!frmfeedback.Recordset.Clone

rst.FindFirst "[id] =" & Me.ID

Forms!frmfeedback.Bookmark = rst.Bookmark

Application.SetOption "Confirm action queries", 0
Application.SetOption "Confirm document deletions", 0
Application.SetOption "confirm record changes", 0

Form.Requery

If chkQ1.Value = False Then
lblQ1na.Visible = True

Else

If chkQ1.Value = True And txtQ1Score.Value > 0 Then
imgQ1tick.Visible = True

Else

If chkQ1.Value = True And txtQ1Score.Value < 1 Then
imgQ1Cross.Visible = True

End If
End If
End If


End Sub
 
What line does it highlight when you get the error?
 
Are you sure your checkbox is named chkQ1 and not chk_Q1 or something else? If it is actually named that see if Me.chkQ1 works instead.
 
Thanks Bob, unfortunatly it still won't work.

I've checked and my check box is definatly called chkQ1. I've tried using me.chkQ1 and get the same error when the code hits chkQ1.

The strange thing is i can run both bits of code independently. It's only when i combine the original code with the IF statements do I get the error.
 
Hi Bob

Can i email to you? I've tried deleting tables and forms but the size of the mdb won't reduce and exceeds the max upload
 
Well, easy to spot when you can see the whole thing :)

Your check box is on the main form, but the code is on the subform. So, you can't reference it via either method. You have to use:

Me.Parent.chkQ1 =
 
Works perfectly - thanks Bob

I didn't realise you needed to reference the main form
 

Users who are viewing this thread

Back
Top Bottom