The below code is meant to tell me if the values selected in two controls already exists in the forms underlying table. So the date is selected first, then after the state is selected, per the On Update event, the code is supposed to check the table data to see if the combination of the reporting date (dt_rpt) and state selected on the form already exist in the underlying table.
I tried to add the rpt date and state as criteria so the lookup wouldn't just give me the first record. It would automatically filter for the values selected on the form controls..
It isn't working. It blows up here:
str_dt_rpt_tbl = DLookup("DT_RPT", "tbl_Data", str_cri_dt)
with an error saying: invalid use of null
Would appreciate some assistance in maybe showing if I have incorrect syntax or the approach is wrong..
Thanks for any help..
Dim str_dt_rpt_tbl As String
Dim str_state_tbl As String
Dim str_dt_rpt_state_tbl As String
Dim str_dt_rpt_state_frm As String
Dim str_msg_rec_exists As String
Dim str_cri_dt As String
Dim str_cri_state As String
str_cri_dt = "DT_RPT = " & Me.txt_DT_RPT
str_cri_state = "STATE = '" & Me.cbo_State & "'"
str_dt_rpt_tbl = DLookup("DT_RPT", "tbl_Data", str_cri_dt)
str_state_tbl = DLookup("STATE", "tbl_Data", str_cri_state)
str_dt_rpt_state_tbl = str_dt_rpt_tbl & str_state_tbl
str_dt_rpt_state_frm = Me.txt_DT_RPT & Me.cbo_State
str_msg_rec_exists = "This reporting period and state already exists in the database. Please reneter a new Reporting Period and State"
If str_dt_rpt_state_frm = str_dt_rpt_state_tbl Then
MsgBox str_msg_rec_exists
Me.cbo_Rpt_Per_MO = Null
Me.cbo_State = Null
End If
I tried to add the rpt date and state as criteria so the lookup wouldn't just give me the first record. It would automatically filter for the values selected on the form controls..
It isn't working. It blows up here:
str_dt_rpt_tbl = DLookup("DT_RPT", "tbl_Data", str_cri_dt)
with an error saying: invalid use of null
Would appreciate some assistance in maybe showing if I have incorrect syntax or the approach is wrong..
Thanks for any help..
Dim str_dt_rpt_tbl As String
Dim str_state_tbl As String
Dim str_dt_rpt_state_tbl As String
Dim str_dt_rpt_state_frm As String
Dim str_msg_rec_exists As String
Dim str_cri_dt As String
Dim str_cri_state As String
str_cri_dt = "DT_RPT = " & Me.txt_DT_RPT
str_cri_state = "STATE = '" & Me.cbo_State & "'"
str_dt_rpt_tbl = DLookup("DT_RPT", "tbl_Data", str_cri_dt)
str_state_tbl = DLookup("STATE", "tbl_Data", str_cri_state)
str_dt_rpt_state_tbl = str_dt_rpt_tbl & str_state_tbl
str_dt_rpt_state_frm = Me.txt_DT_RPT & Me.cbo_State
str_msg_rec_exists = "This reporting period and state already exists in the database. Please reneter a new Reporting Period and State"
If str_dt_rpt_state_frm = str_dt_rpt_state_tbl Then
MsgBox str_msg_rec_exists
Me.cbo_Rpt_Per_MO = Null
Me.cbo_State = Null
End If