Share via

Error with entry search macro

Anonymous
2015-12-09T18:38:39+00:00

I have made a macro for the search of an entry by the value of a particular field. It worked on one computer but when I try to launch it on the other I get the following error. On could be a reason of it and how could I solve it?

This is the code of the macro:

Private Sub mygtukaspa_Click()

If IsNull(kodaspa) = False Then

Me.Recordset.FindFirst "[Kodas]=" & kodaspa

Me!kodaspa = Null

If Me.Recordset.NoMatch Then

MsgBox "Atsiprasome", vbOKOnly + vbInformation, "Irasas nerastas"

Me!kodaspa = Null

End If

End If

Private Sub Tekstas28_Click()

End Sub

Also, this might be off topic but I also get the following error when I launch the query that contains the field with the Date type. Could you help to solve this?

Thank you in advance for your help!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2015-12-11T14:53:05+00:00

    First, what you have is NOT a macro. It is a VBA code snippet. Macros and VBA are two very different things in Access (though that is not true in Excel, Word, etc.). 

    One possible reason you are getting the error on the other machine is that the code doesn't compile on the other machine because of the DataType mismatch error. 

    Datatype mismatches are easy to diagnose. Since the only match I see is in this line:

    Me.Recordset.FindFirst "[Kodas]=" & kodaspa

    I suspect that Kodas is NOT a Number datatype. Or that the control kodaspa contains other than numbers. And I agree with Tom to use Me.kodaspa

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2015-12-11T02:54:43+00:00

    Lithuanian? Cool!

    Before you run any code, use Debug > Compile. Does this code compile?

    Make sure you have "Option Explicit" at the top of every module.

    Me! is not the greatest syntax. Use Me. Long story. More info here: https://groups.google.com/forum/?hl=en#!msg/microsoft.public.access.formscoding/a5WD5Va8yas/JQtah45LGBQJ

    Rather than "kodaspa" write Me.kodaspa. Note the intellisense assistance. Cool! This only works of course if kodaspa is indeed the name of that control (and not just of the underlying bound field).

    What is the data type of the kodaspa field? I'm hoping it's not an OLE field. You can't search on those.

    Re #2.

    Access does not have fields with Date data type. Did you mean Date/Time, or are you perhaps leaving out that you have a SQL Server back-end with a Date field?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-12-11T01:33:54+00:00

    Part one appears to be a Reference issue, have a look at...

    http://www.access-diva.com/d5.html

    I would just looking at the ones on the machine that works and compare to the one that does not work.

    Part two... can you post the SQL of the query?

    Was this answer helpful?

    0 comments No comments