Awes
Usually Confused
- Local time
- Today, 03:50
- Joined
- Aug 20, 2002
- Messages
- 34
Hi Everyone
Starting to tie myself up in knots here so it's time to call on the experts for help again. As usual I apologies for the length of the message but hopefully it is detailed enough to get the answer first ime round.
I am developing a database where a sub-form is used within several different forms.
The sub-form is used to enter information and create a new record. Once the User has entered the relevant information they click on a button.
A check is carried out to ensure that the boxes the client has stipulated as mandatory have been completed and then the record is saved.
I thought it would be a good idea to have a stand alone module to hold the code used to carry out the checking and saving as it is a common process.
Having written the code I am having trouble running it as I keep getting a runtime error (No 5) telling me that there is an Invalid procedure call or argument.
Having done some debug tracing the module is being called ok and the variable I am passing (the name of the form calling the module) appears to transfer to the module, however once the code starts running it is basically telling me that it can't find the form that I have specified.
I'm sure the problem lies in the way that I'm referring to the form/sub-form.
The module code is shown below:
'-------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Public Sub subSaveVehicle(strFormName As String)
'The variable strFormName is the name of the form from which
'this module was called from.
'
'-------------------------------------------------------------------------------
'Declare variables.
Dim dbeMyDb As Database
Dim rstMyset As Recordset
Dim blnErrorStatus As Boolean
'-------------------------------------------------------------------------------
'Initially sets the ErrorStatus flag to FALSE to identify any unexpected errors.
blnErrorStatus = False
'-------------------------------------------------------------------------------
'On error goes to the error handling code.
On Error GoTo ErrorProc
'-------------------------------------------------------------------------------
'Checks the mandatory boxes on the sub-form to ensure that
'there are no empty boxes.
'If one or more empty mandatory boxes are detected the
'ErrorStatus flag is 'set to TRUE to identify a user error.
'This is where the error is occurring, it is telling me it can't find
'strFormName.
If IsNull(Forms!strFormName!frmSubFormName!txtName1) _
Or IsNull(Forms!strFormName!frmSubFormName!txtName2) _
Or IsNull(Forms!strFormName!frmSubFormName!txtName3) Then
blnErrorStatus = True
GoTo ErrorProc 'On error goes to the error handling code.
End If
REST OF CODE GOES HERE
There are other references within the code to
Forms!strFormName!frmSubFormName!xxxxxxx
but the above should be enough to identify the
problem, I hope.
FINISHED:
Exit Sub
'Error handling code.
'If the error is a User error (blnErrorStatus = True) caused by information missing
'from the sub-form a custom error message is displayed.
'Any other error (blnErrorStatus = False) will display the Error Code Number and
'Description.
ErrorProc:
If blnErrorStatus = True Then
MsgBox "Check that all the mandatory boxes have been completed.", _
vbOKOnly, "Missing Information !"
Else
MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly, vbCritical, "Error!"
Resume FINISHED
End If
Resume FINISHED
End Sub
'-------------------------------------------------------------------------------
Any help would be greatly appreciated. Further info can be provided if necessary.
Many thanks
Awes
Starting to tie myself up in knots here so it's time to call on the experts for help again. As usual I apologies for the length of the message but hopefully it is detailed enough to get the answer first ime round.
I am developing a database where a sub-form is used within several different forms.
The sub-form is used to enter information and create a new record. Once the User has entered the relevant information they click on a button.
A check is carried out to ensure that the boxes the client has stipulated as mandatory have been completed and then the record is saved.
I thought it would be a good idea to have a stand alone module to hold the code used to carry out the checking and saving as it is a common process.
Having written the code I am having trouble running it as I keep getting a runtime error (No 5) telling me that there is an Invalid procedure call or argument.
Having done some debug tracing the module is being called ok and the variable I am passing (the name of the form calling the module) appears to transfer to the module, however once the code starts running it is basically telling me that it can't find the form that I have specified.
I'm sure the problem lies in the way that I'm referring to the form/sub-form.
The module code is shown below:
'-------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Public Sub subSaveVehicle(strFormName As String)
'The variable strFormName is the name of the form from which
'this module was called from.
'
'-------------------------------------------------------------------------------
'Declare variables.
Dim dbeMyDb As Database
Dim rstMyset As Recordset
Dim blnErrorStatus As Boolean
'-------------------------------------------------------------------------------
'Initially sets the ErrorStatus flag to FALSE to identify any unexpected errors.
blnErrorStatus = False
'-------------------------------------------------------------------------------
'On error goes to the error handling code.
On Error GoTo ErrorProc
'-------------------------------------------------------------------------------
'Checks the mandatory boxes on the sub-form to ensure that
'there are no empty boxes.
'If one or more empty mandatory boxes are detected the
'ErrorStatus flag is 'set to TRUE to identify a user error.
'This is where the error is occurring, it is telling me it can't find
'strFormName.
If IsNull(Forms!strFormName!frmSubFormName!txtName1) _
Or IsNull(Forms!strFormName!frmSubFormName!txtName2) _
Or IsNull(Forms!strFormName!frmSubFormName!txtName3) Then
blnErrorStatus = True
GoTo ErrorProc 'On error goes to the error handling code.
End If
REST OF CODE GOES HERE
There are other references within the code to
Forms!strFormName!frmSubFormName!xxxxxxx
but the above should be enough to identify the
problem, I hope.
FINISHED:
Exit Sub
'Error handling code.
'If the error is a User error (blnErrorStatus = True) caused by information missing
'from the sub-form a custom error message is displayed.
'Any other error (blnErrorStatus = False) will display the Error Code Number and
'Description.
ErrorProc:
If blnErrorStatus = True Then
MsgBox "Check that all the mandatory boxes have been completed.", _
vbOKOnly, "Missing Information !"
Else
MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly, vbCritical, "Error!"
Resume FINISHED
End If
Resume FINISHED
End Sub
'-------------------------------------------------------------------------------
Any help would be greatly appreciated. Further info can be provided if necessary.
Many thanks
Awes