Me Keyword error

RussMuscle

New member
Local time
Today, 11:07
Joined
Dec 14, 2015
Messages
4
I have a database that we use to keep track of Bid History. It started giving me errors and I don't know of anything that changed. It is a small SQL backend database. I get "no current record" when I first open the database. When I go into the VBA and run the FindHistory portion I get Compile error: Invalid use of Me keyword Not sure what to look for. Here is a copy of the only Module under Modules

Option Compare Database

Function IsLoaded(ByVal strFormName As String) As Boolean

Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)

If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If

End Function


Sub FindHistory()

On Error GoTo Err_cmdDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "BidSchedule"

stLinkCriteria = "[PromoCode]='" & Me![BidID] & "'"
DoCmd.OpenForm BidHistory, , stLinkCriteria

Exit_cmdDetails_Click:
Exit Sub

Err_cmdDetails_Click:
MsgBox Err.Description
Resume Exit_cmdDetails_Click


End Sub
 
Last edited by a moderator:
You can't use Me in a standard module, only in the code behind a form or report. You'll have to either move that to a form/report module, change to the full form syntax, or change it to accept the ID as an input parameter.
 
How would I change it to accept the ID as an input? Would this be something that changed from an older version of access?
 
No, that's been the case as long as I can remember. Me refers to the object containing the code; there is no such object with a standard module. See if this gets you started:

http://www.baldyweb.com/Function.htm
 
Modify your code so it looks more like this.

Code:
Sub FindHistory(frmPassed As Form)
On Error GoTo Err_cmdDetails_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "BidHistory"

    stLinkCriteria = "[PromoCode]='" & frmPassed![BidID] & "'"
    DoCmd.OpenForm stDocName, , stLinkCriteria

Exit_cmdDetails_Click:
Exit Sub

Err_cmdDetails_Click:
MsgBox Err.Description
Resume Exit_cmdDetails_Click

End Sub

I have also change the way the Form name is passed, looks like someone has been messing around with the original code! You will need to call the Sub something like this:-

Code:
Private Sub Command0_Click()

Call FindHistory(Me)

End Sub

The "Me" passes the form as an object, through to the function so that the control value can be extracted from the Instance of the form.
 
Alternatively, without passing a reference to the calling form, if indeed the triggering event is not in frmPassed

stLinkCriteria = "[PromoCode]='" & Forms!frmPassed![BidID] & "'"
 
When I use Uncle Gizmo's code I get this...UncleGizmo.png And when I put in a value it gives me the No Current Record

The information is supposed to display like the Display.png, which is what I get with the original code that quit working for some reason or other.

When I use Cronk's code I get Cannot find the referenced form 'frmPassed'

I appreciate all the help to solve this. Let me know if there is anything else I can provide to help. The original code was working even though evidently it shouldn't have been.
 

Attachments

  • UncleGizmo.png
    UncleGizmo.png
    5.5 KB · Views: 115
  • Display.jpg
    Display.jpg
    35.9 KB · Views: 94
Have a look at the form "BidHistory" Have a look at its record source, I'm thinking it should be "qry_BidHistory"
 
Turned out to be corrupt data that had been input by the user. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom