Suddenly Receiving Run Time Error 2057 (2 Viewers)

I think I'm in dumb mode today, so I am not sure what you are asking.
Code pulls EventID from form and sets value of glngEventID. Then makes another call to form to pull EventID again. Why not use variable just populated?

LTotal = DCount("ImageName", "tblImageFiles", "EventID= " & glngEventID)
 
This doesn't answer the question. I have to make some assumptions here. That is not a function that returns a value and from its syntax, it has no input arguments. This means that whatever it does, it uses global variables, Access objects, or Windows objects to do what it does. But you didn't tell us how it does whatever it does. Is it something you wrote? Did it come from a system or 3rd-party product library? Did you get it online? What IS it?
Concept. A Photo Sharing Solution that works with another application that takes the photos and stores them in a folder (an Event). Once we get to frmEventsNImages, the application gets moved to another monitor that acts as a 'sharing station'. The 'sharing station' is locked out of all forms, reports, etc.

Here's the code. I look for the newest image taken for an event. The form, frmEventsNImages gets opened once. The way this works is all of the Events are displayed in a continuous form called frmEventsList. Several tasks are available for each event, frmEventsNImages is selected when an event is happening (ie, photobooth at a party), so frmEventsNImages gets opened once (to prevent users from going back to frmEventsList, a numeric keypad form is displayed to enter a pin number. This 'locks' various buttons on the form.)

frmEventsNImages shows the event from tblEvents and all of the images taken for that event, sorted with newest image first. This is where sfrmImages comes in. It displays up to six images for the event and the images can be scrolled through. Each image has buttons for sending emails, texts, or printing. sfrmImages is unbound. It is replacing a continuous form that I just don't like the layout.

Code:
Private Sub GetLastImage()
    On Error GoTo ErrorHandler
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSql As String
    Dim strCriteria As String
    strCriteria = Me.EventPath
    strSql = "SELECT ImagePath, ImageName, DateCreated From tblImageFiles  WHERE ImagePath = '" & strCriteria & "' ORDER BY DateCreated DESC"
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSql)
    
    'Since table is sorted by date descending, the newest file is first.  Extract the date
    With rs
    If rs.EOF Then
        MsgBox "No records for " & strCriteria, vbOKOnly, CurrentProject.nam
        Exit Sub
    End If
     .MoveFirst
     dteLastDate = rs![DateCreated]
     Me.txtLastImage = dteLastDate

    End With
    Requery      'this executes Form Current

ExitSub:
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    Exit Sub
ErrorHandler:
    Dim Msg As String
    MsgBox Msg, , "Error" & Str(Err.Number), Err.HelpFile, Err.HelpContext
    Resume ExitSub

End Sub
frmEventsList. Run Event button will launch frmEventsNImages.
1774495163965.png


frmEventsNImages with sfrmImages. The camera button, close button are locked (invisible) to keep users from getting back to frmEventsList
1774495556123.png
 
Code pulls EventID from form and sets value of glngEventID. Then makes another call to form to pull EventID again. Why not use variable just populated?

LTotal = DCount("ImageName", "tblImageFiles", "EventID= " & glngEventID)
Excellent suggestion. I wasn't being too smart when I coded it. Thanks
 
Do you have Option Explicit declared at the top of all your code modules?

Code:
' ...
        MsgBox "No records for " & strCriteria, vbOKOnly, CurrentProject.nam
' ...
Does that code compile?
 
Do you have Option Explicit declared at the top of all your code modules?

Code:
' ...
        MsgBox "No records for " & strCriteria, vbOKOnly, CurrentProject.nam
' ...
Does that code compile?
Always use Option Explicit. Haven’t compiled in a while, so I will check it out.
 
Always use Option Explicit. Haven’t compiled in a while, so I will check it out.
It is at compile time, that those errors are displayed.
Without compiling, you may as well not bother with Option Explicit. :)
 
It is at compile time, that those errors are displayed.
Without compiling, you may as well not bother with Option Explicit. :)
I probably should compile every time I make a coding change but I get to involved.
 
I probably should compile every time I make a coding change but I get to involved.

At least in theory, unless you have diddled with some setting I don't know about, making a change to the code text of a module triggers a recompile of that module on next attempt to execute. This is a selective compile in that other modules stay as-is unless you run a /Decompile operation beforehand. I've even changed a comment in the code text and THAT appeared to trigger a compile.
 

Users who are viewing this thread

Back
Top Bottom