if statement vba in access

mana

Registered User.
Local time
Yesterday, 22:05
Joined
Nov 4, 2014
Messages
265
hello
i wrote the following button in a form
but it doesn't go to the if statement at all
can you help me please?
where is my fault?




If Me.Fehlteil.Value = "" Then
DoCmd.OpenForm "frm_logistik_zeitfehlerein_detail_emptyfields", , , acFormDS
Else

On Error GoTo Err_Befehl14_Click
Dim stDocName As String
Dim stLinkCriteria As String




stDocName = "frm_logistik_zeitfehlerein_detail"

stLinkCriteria = "[Fehlteil]=" & "'" & Me![Fehlteil] & "'"
DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Exit_Befehl14_Click:
Exit Sub
Err_Befehl14_Click:
MsgBox Err.Description
Resume Exit_Befehl14_Click
End If
 
hello
the following is the code



Code:
Private Sub Text52_Click()
  If Me.Fehlteil.Value = "" Then
    DoCmd.OpenForm "frm_logistik_zeitfehlerein_detail_emptyfields", , , acFormDS
    
   Else
On Error GoTo Err_Befehl14_Click
    
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frm_logistik_zeitfehlerein_detail"
    stLinkCriteria = "[Fehlteil]=" & "'" & Me![Fehlteil] & "'"
    DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
Exit_Befehl14_Click:
    Exit Sub
Err_Befehl14_Click:
    MsgBox Err.Description
    Resume Exit_Befehl14_Click
 End If
End Sub
 
hello

did you see the code?
can you say what my problem is please?
 
Your code should be along the lines of below. I always put DIM statements at the top but that is a matter of preference I suppose.

You say it is not going to the If statement?. Have you tried setting a breakpoint on that line and F8 in Debug to see where the code goes.?

Code:
Private Sub Text52_Click()
On Error GoTo Err_Befehl14_Click

  If Me.Fehlteil.Value = "" Then
    DoCmd.OpenForm "frm_logistik_zeitfehlerein_detail_emptyfields", , , acFormDS
    
   Else

    
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frm_logistik_zeitfehlerein_detail"
    stLinkCriteria = "[Fehlteil]=" & "'" & Me![Fehlteil] & "'"
    DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria
 End If
Exit_Befehl14_Click:
    Exit Sub
Err_Befehl14_Click:
    MsgBox Err.Description
    Resume Exit_Befehl14_Click

End Sub
 
Just throwing this out there:

If the value of Me.Fehlteil.Value is null, then the true portion of the if statement will not execute.

Is this what you are seeing? If so, change the if statement to
Code:
If Nz(Me.Fehlteil.Value,"") = "" Then
 
i wrote the following button in a form

and is your button really called text52?

text52 looks like the default name for a textbox, buttons default to command52
 
I think CJ has just spotted your problem. :D
 

Users who are viewing this thread

Back
Top Bottom