Hi All,
I am hoping some kind person will be able to assist my learning curve. I have managed to get through the compile errors with my query but I am battling to get the loop to work correctly.
Basically I have a table called tblIT0008WageTypeValues which holds constant values and looks like this:
WageTypeNum Min
1000 12
1033 750
2050 1000
My data table looks like this:
WT Num BET01
1000 5
1000 50
1000 870
1033 45
1033 3465
1033 9000
2050 500
2050 20000
I have written a query which goes and fires off the code to bring back the records where the "BET01" in the data table is less than the "min" value.
In my query I have the following value in the top line:
Below Min: wagetypechecks([BET01])
My code is as follows:
Option Compare Database
Public Function wagetypechecks(wtamt As String) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim I As Integer
Dim wtmin As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblIT0008WageTypeValues", dbOpenSnapshot)
wtmin = ""
wagetypechecks = False
With rst
For I = 0 To RecordCount
wtmin = .Fields("min")
If wtamt < wagetypechecks Then
wagetypechecks = True
Else: wagetypechecks = False
End If
Next I
End With
End Function
----------------------------------
I have managed to get the code to at least run through. But it returns all the records, whereas I only want it to return the records where the BET01 value is less than the "min" value.
In addition the looping part is not working properly.
I also need it to match up the "wage type num" and "WT Num" and check only the corresponding values when the wage types are equal.
I hope I have been clear in my issue. Please let me know if you need more clarity. I know by looking at the code you will notice that I am still learning VB.
Any help will be most gratefully received.
Thanks,
Evan
I am hoping some kind person will be able to assist my learning curve. I have managed to get through the compile errors with my query but I am battling to get the loop to work correctly.
Basically I have a table called tblIT0008WageTypeValues which holds constant values and looks like this:
WageTypeNum Min
1000 12
1033 750
2050 1000
My data table looks like this:
WT Num BET01
1000 5
1000 50
1000 870
1033 45
1033 3465
1033 9000
2050 500
2050 20000
I have written a query which goes and fires off the code to bring back the records where the "BET01" in the data table is less than the "min" value.
In my query I have the following value in the top line:
Below Min: wagetypechecks([BET01])
My code is as follows:
Option Compare Database
Public Function wagetypechecks(wtamt As String) As Boolean
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim I As Integer
Dim wtmin As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblIT0008WageTypeValues", dbOpenSnapshot)
wtmin = ""
wagetypechecks = False
With rst
For I = 0 To RecordCount
wtmin = .Fields("min")
If wtamt < wagetypechecks Then
wagetypechecks = True
Else: wagetypechecks = False
End If
Next I
End With
End Function
----------------------------------
I have managed to get the code to at least run through. But it returns all the records, whereas I only want it to return the records where the BET01 value is less than the "min" value.
In addition the looping part is not working properly.
I also need it to match up the "wage type num" and "WT Num" and check only the corresponding values when the wage types are equal.
I hope I have been clear in my issue. Please let me know if you need more clarity. I know by looking at the code you will notice that I am still learning VB.
Any help will be most gratefully received.
Thanks,
Evan