AcRecNew Question

  • Thread starter P-chu via AccessMonster.com
  • Start date
P

P-chu via AccessMonster.com

I have grayed out the navigation buttons to add a new record. However, I
need a restriction created on the Add Record button I want users to choose
instead. I created an If clause where if the user failed to enter the right
drop down option and it gives them a message box when they try to leave the
screen, which is what I want. I would like an additional feature on the Add
Button where it does not automatically take you to a new record if the wrong
criteria was selected on the drop down button. Right now they get the
warning message, but still it takes them to a new screen. I've tried many
things, but can't get that working.

Any suggestions please?
 
B

Beetle

Normally you woul just put an Exit Sub inside that portion of your statement;

If Me!MyCombo <> x Then
MsgBox "Invalid selection in the combo box"
Exit Sub
Else
DoCmd.GoToRecord , , acNewrecord
End If
 
P

P-chu via AccessMonster.com

I still seem to be missing something. Here is my code:

Private Sub Form_Unload(Cancel As Integer)
If [Field1] <> 0 And [Combo2] = "standing" Then
MsgBox "Make sure the Combo2 field is changed to FINSIHED."
Cancel = True
Exit Sub
Else
DoCmd.GoToRecord , , acNewrecord

End If

Maybe I have this in the wrong location of the form. I tried to do it on the
add button under "On Enter" or "On Click", but it still takes me to a new
record when I click on the add button. I want to to not let me go to a new
record based on my criteria.
Thanks.
Normally you woul just put an Exit Sub inside that portion of your statement;

If Me!MyCombo <> x Then
MsgBox "Invalid selection in the combo box"
Exit Sub
Else
DoCmd.GoToRecord , , acNewrecord
End If
I have grayed out the navigation buttons to add a new record. However, I
need a restriction created on the Add Record button I want users to choose
[quoted text clipped - 7 lines]
Any suggestions please?
 
B

Beetle

Well it definitely should not be in the forms Unload event. If you have
disabled the standard navigation buttons, and your Add button is the
only way for a user to move to a new record, then it should go in
that buttons Click event. The code should look like;

Private Sub cmdAdd_Click()

If Me![Field1] <> 0 And Me![Combo2] = "standing" Then
MsgBox "Make sure the Combo2 field is changed to FINSIHED."
Me![Combo2].SetFocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If

End Sub

The above assumes that the name of your Add button is cmdAdd. If it
still doesn't work, in other words if it always goes to a new record
regardless, then it means that the first part of the If statement is never
evaluating to True. In that case you should double check all the naming
in the code and make sure that the column in the combo box that holds
the values like "standing" and "Finished" is the bound column (if the
combo box has more than one column).

BTW - you should consider using more descriptive names besides
Field1 and Combo2.

--
_________

Sean Bailey


P-chu via AccessMonster.com said:
I still seem to be missing something. Here is my code:

Private Sub Form_Unload(Cancel As Integer)
If [Field1] <> 0 And [Combo2] = "standing" Then
MsgBox "Make sure the Combo2 field is changed to FINSIHED."
Cancel = True
Exit Sub
Else
DoCmd.GoToRecord , , acNewrecord

End If

Maybe I have this in the wrong location of the form. I tried to do it on the
add button under "On Enter" or "On Click", but it still takes me to a new
record when I click on the add button. I want to to not let me go to a new
record based on my criteria.
Thanks.
Normally you woul just put an Exit Sub inside that portion of your statement;

If Me!MyCombo <> x Then
MsgBox "Invalid selection in the combo box"
Exit Sub
Else
DoCmd.GoToRecord , , acNewrecord
End If
I have grayed out the navigation buttons to add a new record. However, I
need a restriction created on the Add Record button I want users to choose
[quoted text clipped - 7 lines]
Any suggestions please?
 
P

P-chu via AccessMonster.com

Thank you Beetle. This helped me get what I needed. I just used generic
field/combo names only in my example here. I have one last stumbling block,
but I am determined to try to figure it out on my own. Again, thanks much.
Well it definitely should not be in the forms Unload event. If you have
disabled the standard navigation buttons, and your Add button is the
only way for a user to move to a new record, then it should go in
that buttons Click event. The code should look like;

Private Sub cmdAdd_Click()

If Me![Field1] <> 0 And Me![Combo2] = "standing" Then
MsgBox "Make sure the Combo2 field is changed to FINSIHED."
Me![Combo2].SetFocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If

End Sub

The above assumes that the name of your Add button is cmdAdd. If it
still doesn't work, in other words if it always goes to a new record
regardless, then it means that the first part of the If statement is never
evaluating to True. In that case you should double check all the naming
in the code and make sure that the column in the combo box that holds
the values like "standing" and "Finished" is the bound column (if the
combo box has more than one column).

BTW - you should consider using more descriptive names besides
Field1 and Combo2.
I still seem to be missing something. Here is my code:
[quoted text clipped - 27 lines]
 
B

Beetle

You're welcome. Feel free to post back if you have questions about your
other problem.
--
_________

Sean Bailey


P-chu via AccessMonster.com said:
Thank you Beetle. This helped me get what I needed. I just used generic
field/combo names only in my example here. I have one last stumbling block,
but I am determined to try to figure it out on my own. Again, thanks much.
Well it definitely should not be in the forms Unload event. If you have
disabled the standard navigation buttons, and your Add button is the
only way for a user to move to a new record, then it should go in
that buttons Click event. The code should look like;

Private Sub cmdAdd_Click()

If Me![Field1] <> 0 And Me![Combo2] = "standing" Then
MsgBox "Make sure the Combo2 field is changed to FINSIHED."
Me![Combo2].SetFocus
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If

End Sub

The above assumes that the name of your Add button is cmdAdd. If it
still doesn't work, in other words if it always goes to a new record
regardless, then it means that the first part of the If statement is never
evaluating to True. In that case you should double check all the naming
in the code and make sure that the column in the combo box that holds
the values like "standing" and "Finished" is the bound column (if the
combo box has more than one column).

BTW - you should consider using more descriptive names besides
Field1 and Combo2.
I still seem to be missing something. Here is my code:
[quoted text clipped - 27 lines]
Any suggestions please?
 
Top