Open form based on multiple criteria

Nadine67

Board Regular
Joined
May 27, 2015
Messages
225
Hello and thank you for any attention my post may receive.

Windows
Access 2013

I am trying to open a form (frmApproveInitiate) from another form (frmPassword). The user enters the ID number into Text0 on frmPassword and then OK. I added a second criteria where only open the form if table 'Main' fields 'ID' matches and the corresponding field 'Expected Duration' value is > 12.

My code returns Run-time error '2465': can't find field '|1' referred to in the expression. The line of code which has the issue is highlighted in bold below.

My unsuccessful code so far is this:
Code:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
    If IsNull(Me.Text0) Or Me.Text0 = "" Then 'Check that textbox is not Null and not a zero length string
     MsgBox "Whoa there.  You have forgotten to enter an Override ID.  Please answer 'OK' then try again."
     Me.Text0.SetFocus
 '    Cancel = True
     Exit Sub
End If
If DCount("ID", "Main", "ID = " & Me.Text0) = 0 Then 'Check that the input ID exists
     MsgBox "Please enter a valid Override ID"
     Me.Text0.SetFocus
 '    Cancel = True
     Exit Sub
End If
[B]If DCount("ID", "Main", "ID = " & Me.Text0 And [Expected Duration] > 12) = 1 Then[/B]
     MsgBox "You do not have authority to approve this Override."
     Me.Text0.SetFocus
     Exit Sub
End If
DoCmd.OpenForm "frmApproveInitiate", , , , datamode:=acFormEdit, windowmode:=acDialog
Me.Text0.Value = ""
Exit_Command3_Click:
    Exit Sub
Err_Command3_Click:
    MsgBox Err.Description
    Resume Exit_Command3_Click
End Sub

Thank you and have a great day.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hello,

Is it VBA for Excel ... or VBA for Access ...?
 
Upvote 0
Code:
dim where_string as string 
where_string = "ID = " & Me.Text0 & " And [Expected Duration] > 12) " 
debug.print where_string 


If DCount( "ID", "Main", where_string ) = 1 Then
 
Upvote 0
I *think* there is an errant closing bracket in the where_string?

Code:
dim where_string as string 
where_string = "ID = " & Me.Text0 & " And [Expected Duration] > 12) " 
debug.print where_string 


If DCount( "ID", "Main", where_string ) = 1 Then
 
Upvote 0
**** SOLVED ****

I *think* there is an errant closing bracket in the where_string?

Thank you all for your replies. I had my punctuation and brackets in the incorrect place. Thank you for your help......much appreciated!

Code:
If DCount("ID", "Main", "ID = " & Me.Text0) = 1 And DCount("ID", "Main", "[ExpectedDuration] > 12") = 1 Then
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,118
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top