Solved Run-time error 5 - Invalid procedure call or argument (1 Viewer)

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
Hello Arnelgp
yes i have a field memo Updates. I use your correction now but I still get error now in another code like yesterday.

I Dont understand why....this code was working perfectly all the time...
I try debuging and access is showing all the time now that here is the error? whyyyyy

Do you notice any rare in this code?

The purpose of this code is to generate special ID number for items.
The number should be K2022-0001 ...K2022-0002 and so on....
if I comment the yellow markings out ..code generates now only K2022-.... and error 5 dissapear
but i need to generate K2022-0003....
what else i can do?




1655539413455.png
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
I am attaching the database.

The code works correcty if the tblKolone2 is empty.

You then start new enter and access generate K2022-0001. This is perfect.

Then you want new enter..you expect K2022-0002 and we get the error. error 5...
why?

then i delete all the records in the table Kolone2..i start again from begining first enter K2022-0001 generates correcty and then new enter and again error 5....

what i am doing wrong?

If someone can cheeck if you also get error 5 or is something wrong with my computer?
 

Attachments

  • Database6A.accdb
    3.3 MB · Views: 15

CJ_London

Super Moderator
Staff member
Local time
Today, 05:09
Joined
Feb 19, 2013
Messages
14,401
In post #6 the op mentioned recently adding a function to check idle time. This normally requires the use of a timer. Developing when a timer is running is not a good idea. Travelling at the moment so can’t get too involved but can’t see if this has been eliminated as a reason for the issues
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
Hello
yes I delete the idle time. I dont have that anymore.
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
OK maybe I am crazy...
I make this.
Again I take some old database ( delete all the objects) and import all the objects from my last database. This work perfectly. Adding records is working the code which was yellow marking is working good. This is now My new database Db001.

Then I start thinking what I always do before closing the database..I always click on the button compact and repair.
Ok so Then I copy the Db001 and put name Db002. I click the compact and repair..close. Then I enter again into Db002 to enter new data..I get error 5 again...
so in Db001 I didnt yet click compact and repair..and db is working perfectly...

Once you click compact and repair everythink is wrong and is not working correctly???

So my question is? is that possible?

How can I resolve that? why clicking compact and repaire make me problems?
thanks to all
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:09
Joined
Sep 21, 2011
Messages
10,561
I have no idea why.
I used a simpler method to get your new num, but it seems either the Cstr or Clong are at fault?
1655545675207.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:09
Joined
May 7, 2009
Messages
16,421
hi!
instead of Using Dirty Event of the form, you can use BeforeInsert Event:
Code:
Private Sub Form_BeforeInsert(Cancel As Integer)
    'arnelgp
    Dim pattern As String, strNewID As String
    Dim serial As Long
    Dim var As Variant
    serial = 1
    pattern = Format$(Date, "\KYYYY\-")
    strNewID = DMax("KolonaID", "tblKolone2", "KolonaID LIKE '" & pattern & "*'") & ""
    If Len(strNewID) <> 0 Then
        serial = Val(Split(strNewID, "-")(1)) + 1
    End If
    Me!KolonaID = pattern & Format$(serial, "0000")
End Sub
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
Hello Arnelgp
yesssss yessss. Your code now is working. Now I will check all my forms..becouse I have 4 forms that are creating special ID.
I also try compile and repair button and is working. no more error 5. !!!!!!!!!!
It seems it was realy error here..but why? What was causing the error? do you know? I just want to understand:unsure:
how do you know it? :unsure:
So from your code I see that when when will be year 2023
the code ( will do his job? ) and I will have 2023.
pattern = Format$(Date, "\KYYYY\-")
K2023...
is important to have new items starting with 2023 when the year 2023 will be

thank you very much
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:09
Joined
May 7, 2009
Messages
16,421
i don't really know why your db is having error after c&r.
personally, i don't often use c&r.
with microsoft having trouble with their updates, chances are
doing c&r may cause you trouble than good.
so if the size is allowable, avoid it.
if you need to, backup first so you can revert to it in case.

btw, i never use Dirty Event, always BeforeInsert when
on new record.
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
yes i see
thank you very much
now i have a lot of work to do...check all that...test...
ohhh you save me..:)
i was already thinking to do all again from the begining one by one and i have a lot of that..
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:09
Joined
Feb 28, 2001
Messages
22,821
As to an explanation of what was going on... this might be a bit lengthy and part of it is "thinking out loud." I am discussing this only because you mentioned that you used timers on your forms. For active timers and performing development actions, that is like oil and water. They simply do not mix.

Timers tend to be problematic when running in the background, particularly if they are "fast" timers - i.e. short intervals. When developing, you almost certainly do NOT need a timer running. However, you said you had removed the timer from that form. Did you also remember to remove the part that loads the timer interval slot? In any case, you should ALWAYS set up your timers so that they can be turned off for development. Further, it doesn't matter if the form you are developing at the moment has its timer turned off if another form is open in the same project is open in the background and still has ITS timer running. Timers don't just affect a form - they can drag down performance on the entire project.

When I see errors in compilation such as you showed us, I look to the functions called out. In the line that was highlighted yellow in post #21 of this thread, you use CStr(), CLng(), Len(), and IIf(), all of which should be in the VBA library. It would be impossible for you to run ANY VBA code at all if that library was missing. The preceding statements had Left() and Right() functions that are part of the same VBA library - but that statement DIDN'T get called out.

This behavior is indicative of either of two errors. The first error is a type of code corruption that hits randomly and can often by fixed by the DECOMPILE/RECOMPILE process I referenced earlier. The second error is that another library is corrupted in some way. When you are compiling or running the code, Access (behind the scenes) searches for the data needed to validate one or more of the procedure calls, but when it passes over the "screwed up" library reference, it stops and says "invalid procedure call." Not because your call was wrong but because something else stopped it from finding the correct information. That is why earlier I mentioned looking for missing/broken references. This kind of error happens all of the time when there are bad references in the mix.

I have not had that much difficulty with Compact & Repair but if you have timers running ANYWHERE during a C&R you might have issues. We have occasionally noted that developing with active timers caused unexplained corruption. I don't know that a C&R while a timer is running would do that, but I wouldn't rule out at least some corruption potential.

You reported that wiping out the contents of an old but working DB followed by copying everything from the "wonky" DB to the cleaned-out DB worked until you did the C&R. Despite arnelgp's skepticism, I have to say that this cannot happen with any regularity because it is the kind of DB problem that Microsoft would HAVE to fix. AND if it happened often, they would be able to test it more easily. So while I don't doubt your report that a C&R "broke" a working version, I would suggest that something was still active during the C&R and the two active processes interfered with each other in some ugly way. You might want to think about that and remember to do C&R under circumstances that NOTHING in the project could still be active.

I've rambled on a bit, but this leads me to advise you to recheck you project for remnants of those timers. They are great for production but terrible for development.
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
Hello DocMan
yes I just find some code for timers and i say ok i will test it to see how that works. When I developing i am not using timers. I just wanted to see if it is working. Then few days I dint touch access and I forget to remove the timers and then this anoying error 5 started to show.
Then I remove the timers but error 5 still vas alive.
vba editor start to show me that something is wrong with my code who generates special id...then i start thikinking why...
the code was good it gives me correct ID but suddely errror 5 arrrive.
now Arnelgp show me another code and suddenly error 5 gone.
I try to understand why this happen..
now i am afraid if one day my users will use that database and error 5 will show up...ohhh that will be very bad....

one more think ...if it is possible
Arnelgp made me this line of code
I need that here my ID starts with Cs and then the year..example Cs2022-0001
if I write

pattern = Format$(Date, "\CsYYYY\-")
I get
C02022-001

how to write correct so I can get
CS2022-0001?
thank in advance
 

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
I just write it
I am asking anybody who maybe know
hmmm
I try it and I get C0 instead of Cs2022-001
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:09
Joined
Sep 21, 2011
Messages
10,561
So just use another method?
Pattern = "Cs" & Format(Date,"YYYY") & "-" & YourNum

Edit:
With just a little experimentation

? Format$(Date, "\C\sYYYY\-")
 
Last edited:

lacampeona

Registered User.
Local time
Today, 06:09
Joined
Dec 28, 2015
Messages
201
Thank you Gasman
I just didnt know how to write correct syntax :oops:
thanks :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:09
Joined
Sep 21, 2011
Messages
10,561
No neither did I. Hence the experimentation.
 

Users who are viewing this thread

Top Bottom