Compile error: sub or function

G

Guest

The above error occurs when I attempt to select any of the check boxes
that are within this code.

Private Sub Check39_AfterUpdate()
If Check39 = True Then
CheckboxTrue 1
Else: CheckboxFalse 1
End Sub


I am using Access 2003. I've tried everything I could think. Can anyone
help on this?
 
G

Guest

Looks like you're missing an "End If"

Try:
Private Sub Check39_AfterUpdate()
If Check39 = True Then
CheckboxTrue 1
Else
CheckboxFalse 1
End if
End Sub
 
B

Brendan Reynolds

Your code is attempting to call procedures named 'CheckboxTrue' and
'CheckboxFalse'. Have you written procedures by that name? If so, are they
declared in the same form module as the code that is attempting to call
them, or are they declared in another module? If the latter, are they
declared using the Public keyword?

When you get that problem solved, you'll find there's another error with
that code. You're missing the End If from your If ... Then ... Else ... End
If construct.

Here's an example of how working code might look ...

Private Sub Check39_AfterUpdate()

If Check39 = True Then
CheckboxTrue 1
Else: CheckboxFalse 1
End If

End Sub

Private Sub CheckboxTrue(ByVal aNumber As Long)
'do something here
End Sub

Private Sub CheckboxFalse(ByVal aNumber As Long)
'do something here
End Sub
 
G

Guest

I assume that CheckboxTrue and CheckboxFalse are functions that you are
trying to run and pass t them parameters, if so, Try

Private Sub Check39_AfterUpdate()
If Me.Check39 = True Then
CheckboxTrue 1
Else
CheckboxFalse 1
End If
End Sub
 
G

Guest

And did a public function (see code below), but now it is telling me that it
cannot find the form Mothers_Information (Run time error 2450)

Public Function CheckBoxTrue(X As Integer)
Dim dbThe_Mothers_Circle As Database
Dim rstType As Recordset
Dim strSQl As String
Dim MCID As Integer
Dim Check As String

'adds mailing group number to recordset

MCID = Forms!Mothers_Information!MCID
strSQl = "SELECT * FROM Type_of_Participant_Info WHERE MCID = " & MCID
Set dbThe_Mothers_Circle = CurrentDb()
Set rstType = dbjoi.OpenRecordset(strSQl, dbOpenDynaset)
With rstType
.AddNew
.Fields("MCID") = MCID
.Fields("TypeID") = X
.Update
End With
rstType.Close
End Function
 
G

Guest

I have few comments about the code

Public Function CheckBoxTrue(X As Integer)
'============================
'Change it to:
Dim dbThe_Mothers_Circle As Dao.Database
Dim rstType As Dao.Recordset
'============================
Dim strSQl As String
Dim MCID As Integer
Dim Check As String

'adds mailing group number to recordset
'=================================
MCID = Forms!Mothers_Information!MCID
'About the error check again the Form name
'=================================
strSQl = "SELECT * FROM Type_of_Participant_Info WHERE MCID = " & MCID
Set dbThe_Mothers_Circle = CurrentDb()

'=================================
' You need to use the real database name that you defined
Set rstType = dbThe_Mothers_Circle.OpenRecordset(strSQl, dbOpenDynaset)
'=================================
With rstType
.AddNew
'====================
' You realise that you trying to add the same record that
you filtered on? so if it the key you'll get duplicate error
'====================
.Fields("MCID") = MCID
.Fields("TypeID") = X
.Update
End With
rstType.Close
End Function
 
G

Guest

' You need to use the real database name that you defined
Set rstType = dbThe_Mothers_Circle.OpenRecordset(strSQl, dbOpenDynaset

Isn't that what's there? What am I not getting here.
 
G

Guest

You had

Set rstType = dbjoi.OpenRecordset(strSQl, dbOpenDynaset)

Need to be changed to

Set rstType = dbThe_Mothers_Circle.OpenRecordset(strSQl, dbOpenDynaset)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top