I have a form: frmScreen1 with a subform: subFrmScreen1. The the first form has a jobCode, with the subform holding details of versions of the job.
On the first form there is a button cmdNew that when clicked opens up frmScreen2 in a new record for the detail for a new version record. I want to populate the jobCode and Version fields in frmScreen2. The jobCode field is passed fine.
But for the Version field I have created a hidden textbox field on the subFrmScreen1, which counts the number of current versions and adds 1. This value is then passed to frmScreen2. It works fine when there is already +1 versions, but if there are no existing versions I get a 'runtime error: 2427 - You entered an expression that has no value'. So I tried trapping it in an if statement. but then I get a Compile error: type mismatch. I think this has something to do with the variable datatype, but I've tried it as a string and an integer - and get the same error.
I've also tried testing the variable in the if statement is null, is empty, = "".
This is wrecking my head! Please can anyone help me??
Thx in advance.
Here is my code:
***********************************************
Private Sub cmdNew_Click()
Dim strTl As String
Dim strCode As String
Dim iVno As Integer
iVno = SubfrmScreen1.Form!txTotV
If iVno Is Null Then
iVno = 1
Else
iVno = iVno
End If
strCode = Me.GenericJobCode
DoCmd.OpenForm "frmScreen2"
DoCmd.GoToRecord , , acNewRec
Forms!FrmScreen2!GenericJobCode = strCode
Forms!FrmScreen2!Version = iVno
DoCmd.Close acForm, "frmscreen1"
End Sub
On the first form there is a button cmdNew that when clicked opens up frmScreen2 in a new record for the detail for a new version record. I want to populate the jobCode and Version fields in frmScreen2. The jobCode field is passed fine.
But for the Version field I have created a hidden textbox field on the subFrmScreen1, which counts the number of current versions and adds 1. This value is then passed to frmScreen2. It works fine when there is already +1 versions, but if there are no existing versions I get a 'runtime error: 2427 - You entered an expression that has no value'. So I tried trapping it in an if statement. but then I get a Compile error: type mismatch. I think this has something to do with the variable datatype, but I've tried it as a string and an integer - and get the same error.
I've also tried testing the variable in the if statement is null, is empty, = "".
This is wrecking my head! Please can anyone help me??
Thx in advance.
Here is my code:
***********************************************
Private Sub cmdNew_Click()
Dim strTl As String
Dim strCode As String
Dim iVno As Integer
iVno = SubfrmScreen1.Form!txTotV
If iVno Is Null Then
iVno = 1
Else
iVno = iVno
End If
strCode = Me.GenericJobCode
DoCmd.OpenForm "frmScreen2"
DoCmd.GoToRecord , , acNewRec
Forms!FrmScreen2!GenericJobCode = strCode
Forms!FrmScreen2!Version = iVno
DoCmd.Close acForm, "frmscreen1"
End Sub