BeforeUpdate Problem

G

Guest

I'm using a form very similar to Northwind's Order form. When I try to select
the product on the subform I get "Compile error: Sub or Function not defined"
I'm not seeing where the problem could be. The function is from the
ProductIDcbo
as follows:

Private Sub ProductID_BeforeUpdate(Cancel As Integer)
' If Orders Subform is opened as a standalone form, display a message
' and undo changes made to the ProductName text box. (The IsLoaded function
' finds a form in the Forms collection when it's opened as a standalone
' form, but not when it's opened as a subform on a main form.)

Dim strMsg As String
Dim strTitle As String
Dim intStyle As Integer

If IsLoaded("Orders Subform") Then
strMsg = "You can't add or edit a Product Name when you open Orders
Subform as a standalone form."
intStyle = vbOKOnly
strTitle = "Can't Add or Change Product Name"
MsgBox strMsg, intStyle, strTitle
Me!ProductID.Undo
Me.Undo
End If

End Sub

Is this enough information? Am I asking the right question?
I need help with what I could be doing wrong here.
 
R

RuralGuy

I'm using a form very similar to Northwind's Order form. When I try to
select the product on the subform I get "Compile error: Sub or
Function not defined" I'm not seeing where the problem could be. The
function is from the ProductIDcbo
as follows:

Private Sub ProductID_BeforeUpdate(Cancel As Integer)
' If Orders Subform is opened as a standalone form, display a message
' and undo changes made to the ProductName text box. (The IsLoaded
function ' finds a form in the Forms collection when it's opened as a
standalone ' form, but not when it's opened as a subform on a main
form.)

Dim strMsg As String
Dim strTitle As String
Dim intStyle As Integer

If IsLoaded("Orders Subform") Then
strMsg = "You can't add or edit a Product Name when you open
Orders
Subform as a standalone form."
intStyle = vbOKOnly
strTitle = "Can't Add or Change Product Name"
MsgBox strMsg, intStyle, strTitle
Me!ProductID.Undo
Me.Undo
End If

End Sub

Is this enough information? Am I asking the right question?
I need help with what I could be doing wrong here.

You need to have the following Function in a standard module:

Public Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in
' ... Form view or Datasheet view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) _
<> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If

End Function

Post back if you need additional assistance.

HTH
 
G

Guest

Thank you, thank you, thank you!

RuralGuy said:
You need to have the following Function in a standard module:

Public Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in
' ... Form view or Datasheet view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) _
<> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If

End Function

Post back if you need additional assistance.

HTH
 

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

Top