Check for current record (1 Viewer)

HairyArse

Registered User.
Local time
Today, 03:13
Joined
Mar 31, 2005
Messages
92
On various forms on my database I occasionally receive the message "No Current Record".

This is to be expected at certain times as there are indeed no current records.

Now I know it can be suppressed but that's not a course of action I want to take, but is there a way to check for a current record so I can use an if statement to prevent the function from running that causes the No Current Record prompt in the first place?
 

jleach

Registered User.
Local time
Yesterday, 22:13
Joined
Jan 4, 2012
Messages
308
If the current record is not saved, Me.NewRecord returns True

hth
 

HairyArse

Registered User.
Local time
Today, 03:13
Joined
Mar 31, 2005
Messages
92
Hello and thanks for your reply. I'm not checking to see if a new record has been saved, I'm checking to see if there is an actual record.

Let me explain in a bit more depth.

I have a table called tbl_orders which holds a basic summary of an order. There is a field called entry_complete that is an integer. It can have a value of either 0 or -1. When an order is saved, the value of this field changes from a 0 to a -1.

The main form's record source is basically SELECT * FROM tbl_orders WHERE entry_complete = 0

Sometimes this will produce 0 records as there are no currently live orders. Other times, if someone is still working on an order then the live orders will be displayed.

I have various functions that sometimes try and run when there are no current live records and that's when I receive the "No current record" error message. I want to check to current records before each of these functions to prevent the message.
 

jleach

Registered User.
Local time
Yesterday, 22:13
Joined
Jan 4, 2012
Messages
308
What's the nature of these functions? When are you running them? Can you give a few examples?

>> I'm not checking to see if a new record has been saved, I'm checking to see if there is an actual record. <<

If Me.NewRecord = True, then there is no actual record... once a record has been saved for the first time, there's an actual record, whether the status of that record is what you want or not.

In almost all cases, this is enough to keep from running some function against a record that doesn't yet exist (hasn't yet been initially saved).

Code:
If Not Me.NewRecord Then 
   RunMyFunctions()
Else
  'do whatever you want when there's no current record
End If

The source of Access's "No Current Record" error is generally the result of trying to run a function when the record has not been initially saved yet.

You can attempt to force the save of a record before running your function, if that helps:

Code:
If Me.NewRecord Then
  DoCmd.RunCmd acCmdSaveRecord
End If

RunMyFunctions()

(however, you'll need good error handling here in case the record can't be saved for some reason).

Anyway, I'm not quite sure I understand the situation completely. Examples of the functions you're trying to run and when you're running them would help quite a bit.

Cheers,
 

HairyArse

Registered User.
Local time
Today, 03:13
Joined
Mar 31, 2005
Messages
92
Thanks for your reply Jack.

Examples of the custom functions I'm running are as follows:

Check the current record's customers' VAT status to determine how much VAT to charge.

Field validation. If mandatory fields are not filled in then set their border to be red an 2 pixels thick to draw attention to them.

Forced refresh.

I also occasionally get the No Current Record error when simply closing a form.

I'll give your suggestion a try and see if I can eliminate the problem.

Thanks again.
 

Users who are viewing this thread

Top Bottom