Click Vs Double Click (1 Viewer)

mtagliaferri

Registered User.
Local time
Today, 08:45
Joined
Jul 16, 2006
Messages
519
Following yesterday post that went missing after the crash....

As click and double click on the same text box can be tricky I need to be able to double click on a text box that if it empty will open form A if it has a value already will open form B.
I was recomended yesterday to use the If Else statement, I have done so but it is still not working.

Code:
Private Sub Staff_Number_DblClick(Cancel As Integer)
On Error GoTo Err_DblClick_Click

    If RoomNumber = Null Then
    DoCmd.OpenForm "frmA", acNormal, "", "", acEdit, acDialog

Else
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmB"
   
    stLinkCriteria = "[IDRoomNumber]=" & Me![IDRoomNumber]
    
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    

Exit_DblClick_Click:
    Exit Sub

Err_DblClick_Click:
    MsgBox Err.Description
    Resume Exit_DblClick_Click
    End If
End Sub

I get an error "Syntax error (missing operator) in query expression '[IDRoomNumber]=' .

Any help pleasee :banghead:
 

Ranman256

Well-known member
Local time
Today, 03:45
Joined
Apr 9, 2015
Messages
4,337
its too risky to have click and dbl-click events on 1 box.
but
for code: IF ISNULL(txtBox) THEN

for queries: txtbox is null
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:45
Joined
May 7, 2009
Messages
19,230
You cant compare anything to null. So

If RoomNumber = Null Then

Is not valid. Use:

If IsNull(RoomNumber) Then

Instead.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:45
Joined
Feb 19, 2002
Messages
43,257
There is NO problem having code in both click and double-click events although typically you don't put code in the click events of textboxes. If you do, the code will run twice because the first click will fire the click event and the second will fire the double-click event.

As the others mentioned, the actual problem is with how you are checking for null. A future problem will be that Null is not the same as a ZLS string and you actually need to account for both. I've restructured your code - it is not correctly formatted which makes it harder than necessary to read and you have procedure labels inside an If statement. Although technically, this is allowed, you really shouldn't be doing it unless you actually need to and this code does not need to.
Code:
Private Sub Staff_Number_DblClick(Cancel As Integer)

    Dim stLinkCriteria As String

    On Error GoTo Err_DblClick_Click

    If Me.RoomNumber & "" = "" Then
        DoCmd.OpenForm "frmA", , , , , acDialog
    Else  
        stLinkCriteria = "[IDRoomNumber]=" & Me.[IDRoomNumber]    
        DoCmd.OpenForm "frmB", , stLinkCriteria
    End If  

Exit_DblClick_Click:
    Exit Sub

Err_DblClick_Click:
    Select Case Err.Number
    Case Else
        MsgBox Err.Number & "--" & Err.Description
        Resume Exit_DblClick_Click
    End Select

End Sub
 

Users who are viewing this thread

Top Bottom