Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where Condition not working 3

Status
Not open for further replies.

jdwm2310

Technical User
Jul 26, 2001
396
US
Hi,

I have a form which has several command buttons these buttons will either open a form for viewing, adding, or editing.
There is one particular button that is giving me a hard time, which is "Pending Tickets" When the user logs on (using a global variant)and clicks on this option the PendingTicket form should open allowing them to edit their own Pending Tickets. Could someone please look at my code and hopefully spot something that I missed....Thanks

[tt]Private Sub ViewingPendingTickets_Click()
DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = 'Forms!Log![cbousername]"
End Sub[/tt]
 
You have :

Code:
DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = 'Forms!Log![cbousername]"

This is looking for a UserName of "Forms!Log![cbousername]"

However, I suspect that you want a UserName that matches the VALUE held in the control Forms!Log![cbousername]

So what you need is
Code:
DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = '" & Forms!Log!cbousername & "'"


QED.

G LS
 
I paste the code you provided:
[tt]DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = '" & Forms!Log!cbousername & "'" [\tt]

But I get a Run-Time Error '13'
Type Mismatch?
 
if cbousername is a number then "Username =" & forms!log!cbousername
 
Error 13 indicates to me that UserName is not really a NAME aferall it is a UserNameRef ( A Number )

Try
Code:
DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = " & Forms!Log!cbousername

G LS
 
Error 13 indicates to me that UserName is not really a NAME aferall it is a UserNameRef ( A Number ).

Try
Code:
DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending'" And "UserName = " & Forms!Log!cbousername

G LS
 
UserName is a text field.It is a string from the LogOn Name. So if I log on, my name will appear in the UserName text in the form.

When I tried the revised code, I still get the same error???
 
Hi!

Use this:

DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending' And UserName = '" & Forms!Log!cbousername & "'"

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks Jeff it works marvelous....you guys came through once again.....

One more thing,how can I include a message when the user has no Pending Tickets
 
Hi!

You can do it like this in the PendingTicket's Form_Open event procedure:

Dim rst As DAO.Recordset

Set rst = Me.RecordsetClone

If rst.EOF = True And rst.BOF = True Then
Call MsgBox("No Ticket!")
Cancel = -1
End If

Set rst = Nothing

hth
Jeff Bridgham
bridgham@purdue.edu
 
it seems to work i inserted the code in the Open event in the PendingTicket form...I get the message I click on ok, and then i get a Run Time Error 2501 - The Openform action was canceled..
 
Hi again!

In the event where you open the form do this:

On Error GoTo Err_Handler

DoCmd.OpenForm "PendingTickets", , , "TicketStatus = 'Pending' And UserName = '" & Forms!Log!cbousername & "'"

Err_Handler:

If Err.Number = 2501 Then
Resume Next
End If

hth
Jeff Bridgham
bridgham@purdue.edu
 
Wow you guys are amazing....Job well done like always!!!!!!!! [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top