How to Skip/Ignore VBA Function/Private Sub?

Heatshiver

Registered User.
Local time
Today, 10:20
Joined
Dec 23, 2011
Messages
263
I have some code that checks the date AND user ID to ensure that there has not been a record for that date and user ID on Form B. This works without issue. On the same form I have a text box to input a new date with a command button that then copies over all the records information and then creates a new record with that new date. This works if I comment out the code that checks out the date and user ID.

When the user first gets into the database they input the user ID on Form A, and then Form B pops up. On the load event of Form B, it takes the user ID from Form A and places it in the user ID of Form B, which is locked.

My problem is that if I enable the code for the data and user ID check, it causes the database to hang when the user tries to have the record copied over to a new one.

My question is how can I tell the button that when clicked ignore, skip, or temporarily disable the code that checks the date and user ID?
 
Put a logical test at the start of the code you and use the Exit Sub command to bail out of the procedure and not run the rest of the code.
 
I thought your suggestion would work, but no matter how I try it, it still hangs on my database due to the check date and user ID code...

Here is what I have:


Private Sub cmdOldValues_Click()

On Error GoTo Err_cmdOldValues_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdPasteAppend

Me.Days.Value = Me.txtDate.Value

DoCmd.OpenForm "frmUserID", acNormal
[Forms]![frmUserID].Visible = False

[Forms]![frmUserID]![UserID].Value = Me.UserID.Value

Exit_cmdOldValues_Click:
Exit Sub

Err_cmdOldValues_Click:
MsgBox "Error"
Resume Exit_cmdOldValues_Click

End Sub



For whatever reason, the rest of the forms' codes are read and it gets to my code for the date and user ID check, then hangs.
 
Not sure why it didn't dawn on me earlier, but all I should need to do is place the Exit Sub in the code for the check on the date and user ID, state that if the button is clicked then exit the code for the check. I'll reply once I try it.
 
I tried:

If cmdOldValues_Click = True Then
Exit Sub
End If


But I continue to get the error: Expected Variable of Function
 
Ended up using cmdOldValues.Enabled = True and this worked in place of _Click = True
 
So like John Big Booty said, you need to put a logic test. For example you can test against a boolean variable, set the variable to False when you're copying and set it to True otherwise. When testing, if it's False do not perform the validation.
 
I tried:

If cmdOldValues_Click = True Then
Exit Sub
End If

But I continue to get the error: Expected Variable of Function

This error occurs because cmdOldValues_Click is defined as a Sub and not a Function, so it does not return the value that you are looking for.

I also believe that cmdOldValues.Enabled will always be True, unless you are turning the Button on and off in VB Code.

-- Rookie
 

Users who are viewing this thread

Back
Top Bottom