Do not Do if field is empty? (1 Viewer)

Jarichardusa

New member
Local time
Today, 16:23
Joined
May 23, 2020
Messages
19
so I have a filter set up on my main page to filter the results in a subform datasheet. I have a button to open another form to do some stuff, and when that form is closed I would like it to refresh the filter if it was already filtered before opening the secondary form up, essentially so the user will just be brought back exactly where they left from but with the new record showing, it it falls within the filter. But, if it wasn't already filtered, so there are no dates in the filter boxes, it fails with an error. What code is needed in order to essentially skip the filtering if the filter button is pressed but the fields are blank so that it just does nothing instead of erroring out?
 

CarlettoFed

Member
Local time
Today, 22:23
Joined
Jun 10, 2020
Messages
119
Perhaps if you attach the file and indicate the mask involved it would be easier and faster to give you a solution, because it is not clear what you want to do.
 

Ranman256

Well-known member
Local time
Today, 16:23
Joined
Apr 9, 2015
Messages
4,337
open the new record by using the key:

'save new record, then get the key
DoCmd.RunCommand (acCmdSaveRecord)
vKey = me.txtID
sFrm = me.name

'then open the previous form w the new record
docmd.openform "frmMyForm",,,"[id]=" & vKey

'close the make new rec form
docmd.Close acForm , sFrm
 

Jarichardusa

New member
Local time
Today, 16:23
Joined
May 23, 2020
Messages
19
Perhaps if you attach the file and indicate the mask involved it would be easier and faster to give you a solution, because it is not clear what you want to do.

Okay, sorry for making it confusing. this is the code for the filter button:

Code:
Private Sub btnDateRange_Click()
Dim Filter As String

Filter = "[WageDate] Between #" & Format(Me!TxtStartDate.Value, "yyyy\/mm\/dd") & "# And #" & Format(Me!txtEndDate.Value, "yyyy\/mm\/dd") & "#"

Me!sbfrm_qryDeliveries.Form.Filter = Filter
Me!sbfrm_qryDeliveries.Form.FilterOn = True
End Sub

I just want it so that if that same code is ran, but the referenced fields are empty, then instead of giving an error, it just does nothing as if the button was never even clicked. Once I know how to make that happen, then I can apply it to what I'm trying to do.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:23
Joined
May 21, 2018
Messages
8,527
If isdate(me.txtstartDate) and isdate(me.txtEndDate) then
filter code here
else
Me!sbfrm_qryDeliveries.Form.FilterOn = false
end if
 

Jarichardusa

New member
Local time
Today, 16:23
Joined
May 23, 2020
Messages
19
I apologize for my ignorance, but where do I put that statement into the code that is already there?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:23
Joined
May 21, 2018
Messages
8,527
Filter code here
 

Users who are viewing this thread

Top Bottom