View Single Post
Old 09-11-2019, 05:51 PM   #9
Newly Registered User
Join Date: Jul 2019
Posts: 105
Thanks: 2
Thanked 0 Times in 0 Posts
Lkwdmntr is on a distinguished road
Re: DLookup not working

If the StandardActions table doesn't have a WeekNumber that is equal to 2, then it should open the Edit_Standard_Actions form. Here is my revised code. I'm testing it with no week 2 in the table and it is still advancing to the Else part of the statement.
Dim Id As Integer, wkNum1 As Integer, wkNum2 As Integer, Status As String, lookupwk1 As Integer, lookupwk2 As Integer

Id = Form_FRM_Select_Users.SelectUserID.Value
wkNum1 = 1
wkNum2 = 2

If DLookup("[WeekNumber]", "Standard_Actions", "[UserID]=" & Id & " And [WeekNumber] =" & wkNum1) <> 1 Then
DoCmd.OpenForm "FRM_Meal_Categories", acNormal, , , acFormAdd
Form_FRM_Meal_Categories.UserID.Value = Id
Form_FRM_Meal_Categories.WeekNumber.Value = wkNum1
Form_FRM_Meal_Categories.FullName.Value = DLookup("[FullName]", "Users", "[UserID]=" & Id)
Form_FRM_Meal_Categories.Before_Breakfast_Snack.Se tFocus
DoCmd.Close acForm, "FRM_Select_Users"
If DLookup("[WeekNumber]", "Standard_Actions", "[UserID]=" & Id & " And [WeekNumber] =" & wkNum2) <> 2 Then
DoCmd.OpenForm "FRM_Edit_Standard_Actions", , , "UserID =" & Id & " And " & "WeekNumber =" & wkNum2, acFormEdit
Form_FRM_Edit_Standard_Actions.UserID.Value = Id
Form_FRM_Edit_Standard_Actions.WeekNumber.Value = wkNum1
DoCmd.Close acForm, "FRM_Select_Users"
MsgBox "You have already created a plan for this user. If you would like to edit week one, select 'Edit Existing User' in the Main Menu.", vbOKOnly
DoCmd.OpenForm "MainMenu", acNormal
DoCmd.Close acForm, "FRM_Select_Users"
End If
End If
Sorry, been unable to look at this for a couple of days. I'm in a coding boot camp and we have 23 chapters to read by Sunday. Been a little busy.
Lkwdmntr is offline   Reply With Quote