I am getting said error in case when my loop is hitting situation having no data in table feild, i have searched on net and found that i need to insert if statement to check the set value is null. I tried but I am unable to find solution, see if anyone can help .. Thx in advance
Private Sub BtnTotal13To24_Click()
Dim db As DAO.Database ' declaring dao databse
Dim rst As DAO.Recordset ' declaring dao recordset
Dim strSQL As String ' string for select statement to opend table data
Dim pcsid, pcsid1, y, x, z As Integer
Dim strQuery As String ' for dsum condition, conditon of first and 12th value of field and matching fabirc received id of table and form
Set db = CurrentDb ' set db as current db
strSQL = "SELECT * FROM TblFabricPieceEntry WHERE FabricReceiveID = " & Me!FabricReceiveID ' select statement for opending databse witch condition
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset) ' opening table
x = 0 'for finding 1st value in table
z = 0 ' for segrigating dsum in correct textbox
For y = 0 To 2 Step 1
rst.Move (x) 'finding 1st value and then 13th , 23rd...
pcsid = rst!FabricPieceID ' assigning value to 1st variable
'Debug.Print pcsid
rst.Move (11) 'finding 12th value and then 24th , 36rd...
pcsid1 = rst!FabricPieceID ' assigning value to 2nd variable
'Debug.Print pcsid1
strQuery = "[FabricPieceID] between " & pcsid & " and " & pcsid1 & "And" & "[FabricReceiveID] = " & Me!FabricReceiveID
'placing variable in string with second condition
Select Case z
Case Is = 0
Me.TxtTotal1To12.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
Me.TxtTotal13To24.Value = 0
Me.TxtTotal25To36.Value = 0
'for filling up 1st text box of 1st loop
Case Is = 1
Me.TxtTotal13To24.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
Me.TxtTotal25To36.Value = 0
'for filling up 2nd text box of 2nd loop
Case Is = 2
Me.TxtTotal25To36.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
'for filling up 3rd text box of 3rd loop
Case Else
MsgBox "error"
End Select
z = z + 1
x = 1
Next y
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Sub
Private Sub BtnTotal13To24_Click()
Dim db As DAO.Database ' declaring dao databse
Dim rst As DAO.Recordset ' declaring dao recordset
Dim strSQL As String ' string for select statement to opend table data
Dim pcsid, pcsid1, y, x, z As Integer
Dim strQuery As String ' for dsum condition, conditon of first and 12th value of field and matching fabirc received id of table and form
Set db = CurrentDb ' set db as current db
strSQL = "SELECT * FROM TblFabricPieceEntry WHERE FabricReceiveID = " & Me!FabricReceiveID ' select statement for opending databse witch condition
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset) ' opening table
x = 0 'for finding 1st value in table
z = 0 ' for segrigating dsum in correct textbox
For y = 0 To 2 Step 1
rst.Move (x) 'finding 1st value and then 13th , 23rd...
pcsid = rst!FabricPieceID ' assigning value to 1st variable
'Debug.Print pcsid
rst.Move (11) 'finding 12th value and then 24th , 36rd...
pcsid1 = rst!FabricPieceID ' assigning value to 2nd variable
'Debug.Print pcsid1
strQuery = "[FabricPieceID] between " & pcsid & " and " & pcsid1 & "And" & "[FabricReceiveID] = " & Me!FabricReceiveID
'placing variable in string with second condition
Select Case z
Case Is = 0
Me.TxtTotal1To12.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
Me.TxtTotal13To24.Value = 0
Me.TxtTotal25To36.Value = 0
'for filling up 1st text box of 1st loop
Case Is = 1
Me.TxtTotal13To24.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
Me.TxtTotal25To36.Value = 0
'for filling up 2nd text box of 2nd loop
Case Is = 2
Me.TxtTotal25To36.Value = DSum("[ReceiveGreyFabricMeter]", "TblFabricPieceEntry", strQuery)
'for filling up 3rd text box of 3rd loop
Case Else
MsgBox "error"
End Select
z = z + 1
x = 1
Next y
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Sub