Run-time error '3021' No current record. (1 Viewer)

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
Hi Im new to access, ive taken over a programme that someone made before they left the business and now one of the files that I am trying to enter into the system comes up with this error. It stays in there and all the information is there but when you try and print preview, print or save it comes up with this error. I don't understand as the record is there and so is everything that needs to make it run.

Im guessing this is VBA as I have seen a similar post on here but didn't quite understand how to make that work.

Help please.
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
What is the code associated with this print?
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
Hi Paul, You helped her a few times with this database. Her name is Holly.

Please see attached the VBA

Thanks for your help.
 

Attachments

  • Debug.PNG
    Debug.PNG
    43.8 KB · Views: 451

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
I remember explaining what DoCmd.SetProperty does to someone, not sure if it was Holly_Associated. Anyway, the function you are using does not set filters. It sets properties of the Object like Width, Height, Visibility etc.

What is that you are actually trying to do? Based on your experiments, you want to filter/find a record and print it. Is this observation correct? If so, you need the DoCmd.OpenReport's WHERE Condition.
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
Yes it was Holly_Associated. Shes my cousin. Basically there is a section In this database that allows you to write in what happened on our Jobs. Daily Site Diaries. All of the others work fine and are all based upon the same coding and the same tables etc. But there is one that I have found that I cannot save or print the diary to. When you print these off they just come up with #Type! on all of the boxes. However if you come out of the database all together and then go back into it, all the information is there you just cant print or save it. I would ask her but shes just started a new job and don't want to bother her with her old job :)

Thanks Paul
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
When you go into the table where the record is stored it comes up with the same error but the information is stored just like the rest of them. And yes she is my cousin lol.

Thanks
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
Could you upload a Stripped DB?

How to Upload a Stripped DB.

To create a Sample DB (to be uploaded for other users to examine); please follow the steps..

1. Create a backup of the file, before you proceed..
2. Delete all Forms/Queries/Reports that are not in Question (except the ones that are inter-related)
3. Delete auxiliary tables (that are hanging loose with no relationships).
4. If your table has 100,000 records, delete 99,990 records.
5. Replace the sensitive information like Telephone numbers/email with simple UPDATE queries.
6. Perform a 'Compact & Repair' it would have brought the Size down to measly KBs..
7. (If your Post count is less than 10 ZIP the file and) Upload it..

Finally, please include instructions of which Form/Query/Code we need to look at. The preferred Access version would be A2003-A2007 (.mdb files)
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
Had a minor set back. Deleted all the addresses after doing the back up and the back up took that into account and has deleted all the addresses permanently. But whilst I a doing this, could you help with one other thing. We have another database that Holly made for labels. Completely separate from this one. It is coming up with this error. Run time error 94 invalid use of null. Below is the code that goes with that.

Option Compare Database
Option Explicit

Public Function ClientFirstLineModule(firstLVar As Variant, streetVar As Variant) As String

Dim cflStr1 As String, startingposition As Integer, cflStr2 As String

startingposition = InStr(streetVar, ",")

cflStr1 = IIf(firstLVar = "Small Client A-M" Or firstLVar = "Small Client N-Z", Left(streetVar, (startingposition)), firstLVar)

cflStr2 = IIf(firstLVar = "Small Client A-M" Or firstLVar = "Small Client N-Z", Left(cflStr1, Len(cflStr1) - 1), firstLVar)

ClientFirstLineModule = cflStr2

End Function

The one that it is highlighting is

startingposition = InStr(streetVar, ",")
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
Try this code,
Code:
Option Compare Database
Option Explicit

Public Function ClientFirstLineModule(firstLVar As Variant, streetVar As Variant) As String
    Dim cflStr1 As String, startingposition As Integer, cflStr2 As String
    If IsNull(firstLVar) Or IsNull(streetVar) Then
        ClientFirstLineModule = vbNullString
        Exit Function
    End If
    
    startingposition = InStr(streetVar, ",")
    
    If firstLVar = "Small Client A-M" Or firstLVar = "Small Client N-Z" Then
        cflStr1 = Left(streetVar, startingposition)
        cflStr2 = Left(cflStr1, Len(cflStr1) - 1)
    Else
        cflStr2 = firstLVar
    End If
    
    ClientFirstLineModule = cflStr2
End Function
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
Ok 2 problems, the code now doesn't bring up the message which is good news. But now no addresses are showing and I don't know how to bring up that vba code box without the error message :-|
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
Your problem is because either of the two arguments you are passing to this function is Null. Acess String function cannot handle Null. The code I have given you will; if found a Null in one of the two arguments will give you a Null String (vbNullString).
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
So how do I get it to show the addresses without the error message? Sorry I don't do VBA.
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
Okay imagine this.

You have a Juicer, this machine is only capable of handling Apples. So, if you want Apple juice; you put two Apples in the Juicer. Result will be a glass of Apple Juice.

You put two Peaches (or) One Apple and One Peach in the Juicer. The machine will break and you will get a huge bill in your hand, not Apple juice.

So replace the words Apple with Strings, Juicer/machine with Function. Apple Juice with Address String. Null Values (Variant) is Peaches. So what I have done is check if the Input fruits are Peaches (even if one of them is peach) you safely say I cannot make you a juice, so the result is nothing.

What you are trying to do is: You want to put Peaches in the Juicer but expect a Glass of Apple juice. So your options are limited, you either get a bill for repair (Error) or Nothing (because you cannot expect Apple juice from a Apple juicer when you give Peaches). Makes sense?
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
kinda, I really want a glass of apple juice now tho :p So to make this work I have to make sure that everything that I am asking it to do is there and available and Im not asking it to do something that it cant do because ive not given it that function. What I don't understand is it was working before and now it has decided to stop.
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
What I don't understand is it was working before and now it has decided to stop.
No it was not, it was simply hiding the errors, probably with some conditional formatting or the Query would simply give up. The error would have probably be hidden.

If you really need an Apple Juice I would need the whole kitchen (maybe not the whole pantry, just the Mixer, some fruits to play with). ;)
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
So how do I get the code you gave me to give me apple juice/ Addresses.
Sorry as I said I don't do VBA. I get how to do certain expressions but even they are a bit too complicated.

Option Compare Database
Option Explicit

Public Function ClientFirstLineModule(firstLVar As Variant, streetVar As Variant) As String
Dim cflStr1 As String, startingposition As Integer, cflStr2 As String
If IsNull(firstLVar) Or IsNull(streetVar) Then
ClientFirstLineModule = vbNullString
Exit Function
End If

startingposition = InStr(streetVar, ",")

If firstLVar = "Small Client A-M" Or firstLVar = "Small Client N-Z" Then
cflStr1 = Left(streetVar, startingposition)
cflStr2 = Left(cflStr1, Len(cflStr1) - 1)
Else
cflStr2 = firstLVar
End If

ClientFirstLineModule
 

pr2-eugin

Super Moderator
Local time
Today, 19:26
Joined
Nov 30, 2011
Messages
8,494
Please give me a Stripped DB. You are giving me Code, I can read code, edit code and modify it, but without data I cannot guarantee a result.
 

Sarah Byrne

Registered User.
Local time
Today, 11:26
Joined
Feb 27, 2014
Messages
88
The last time I tried to do that I lost all my first line to my addresses for the other database :-( Still trying to get them back. I don't want to try and strip this one as I think il do it again and this one I wont be able to get them back and il have a lot of angry faces. I can screen shot some stuff for you. I know how to do that :)
 

Users who are viewing this thread

Top Bottom