paulcraigdainty
03-21-2008, 04:50 AM
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
gemma-the-husky
03-21-2008, 05:49 AM
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
paulcraigdainty
03-22-2008, 12:08 AM
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
boblarson
03-22-2008, 12:18 AM
What line does it highlight when you get the error?
paulcraigdainty
03-22-2008, 12:19 AM
hi Bob,
It's the first line of the IF statement - If chkQ1.Value = False Then
boblarson
03-22-2008, 12:21 AM
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.
paulcraigdainty
03-22-2008, 12:34 AM
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.
paulcraigdainty
03-22-2008, 12:53 AM
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
boblarson
03-22-2008, 12:53 AM
Have you followed the entire process here:
http://www.access-programmers.co.uk/forums/showthread.php?t=140587
paulcraigdainty
03-22-2008, 12:58 AM
No I hadn't, thanks Bob. Here it is, you'll find the problem code in the on click event of the Date text box on the subform of frmFeedback
boblarson
03-22-2008, 01:04 AM
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 =
paulcraigdainty
03-22-2008, 01:36 AM
Works perfectly - thanks Bob
I didn't realise you needed to reference the main form