If statement with two criteria (1 Viewer)

zulu100

Member
Local time
Today, 18:19
Joined
Nov 3, 2021
Messages
54
Hi
I have a button on form "frm_ctn_List" called btn_StopOrdre. In the "on click" event of this I would like to show a msgbox if
field [MedarbejderID] in table "tbl_TidsTabel" equals combobox "cbm_Medarbejder" value.
and field [On] in table "tbl_TidsTabel" equals 0
Otherwise open form "frm_ctn_TidStop"
The openform criteria is working properly but first "if" statement is wrong

The combobox "cbm_Medarbejder" is in the current form.

Code:
If "MedarbejderID=" & cbm_Medarbejder.Value & "and [on]= 0" Then
MsgBox "Denne produktionsordre er ikke startet endnu!", vbOKOnly
Else
DoCmd.OpenForm "frm_ctn_TidStop", , , "MedarbejderID=" & cbm_Medarbejder.Value & "and [off]= 0", acFormEdit, acWindowNormal
End If
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:19
Joined
Sep 21, 2011
Messages
14,044
You have surrounded the field name with " ?
Use Dlookup() to check the values?
 

SHANEMAC51

Active member
Local time
Today, 20:19
Joined
Jan 28, 2022
Messages
310
е.

[КОД] Если "MedarbejderID=" & cbm_Medarbejder.Value & "and [on]= 0", то
MsgBox "Denne produktionsordre er ikke startet endnu!", vbOKOnly
Еще
DoCmd.OpenForm "frm_ctn_TidStop", , ,"MedarbejderID=" & cbm_Medarbejder.Value & "and [off]= 0", acFormEdit, acWindowNormal
Окончание если[/КОД]
Code:
If  len("" & cbm_Medarbejder.Value )=0 Then
MsgBox "Denne produktionsordre er ikke startet endnu!", vbOKOnly
Else
DoCmd.OpenForm "frm_ctn_TidStop", , , "MedarbejderID=" & cbm_Medarbejder.Value & "    and  [off]= 0", acFormEdit, acWindowNormal
End If
 

zulu100

Member
Local time
Today, 18:19
Joined
Nov 3, 2021
Messages
54
You have surrounded the field name with " ?
Use Dlookup() to check the values?
I am not sure how to add the last criteria.
I get an error on this one


Code:
If DLookup("[MedarbejderID]", "tbl_TidsTabel", "MedarbejderID = " & cbm_Medarbejder.Value & "") And [On] = 0 Then
 

SHANEMAC51

Active member
Local time
Today, 20:19
Joined
Jan 28, 2022
Messages
310
Code:
If DLookup("[MedarbejderID]", "tbl_TidsTabel", "MedarbejderID = " & cbm_Medarbejder.Value & " And [On] = 0") Then
 

zulu100

Member
Local time
Today, 18:19
Joined
Nov 3, 2021
Messages
54
Thanks..
Maybe my logic is off. I cant seem to make it work
First I make sure that the user has made a choice in the combobox with this.

Code:
    Dim intanswer As Integer

    If IsNull(Forms!frm_ctn_List!cbm_Medarbejder) Then
    intanswer = MsgBox("Husk... Vælg medarbejder fra dropdown list", vbOKOnly)
    Forms!frm_ctn_List!cbm_Medarbejder.SetFocus
    Else
    DoCmd.OpenForm "frm_ctn_TidStop", , , "MedarbejderID=" & cbm_Medarbejder.Value & "and [off]= 0", acFormEdit, acWindowNormal
    cbm_Medarbejder.Value = Null
    End If

Additionally.

Now this is a time sheet form for employees so I would also like to make sure that the operator can't log out of a production order that he or she hasn't logged in to yet.
The conditions for a validating a production order not logged in to is:
[StartTid] = "" in "tbl_TidsTabel"
[On] = 0 in "tbl_TidsTabel"
[MedarbejderID] = cbm_Medarbejder.Value on form "frm_ctn_List"
[No_] = Selected record on form "frm_ctn_List"

A time log record is not added before a operator log in to a production order so I don't know what to validate up against since the record hasn't been created.
Maybe I am missing some very simple thing here
 

Attachments

  • tbl.png
    tbl.png
    13.3 KB · Views: 251

Users who are viewing this thread

Top Bottom