Solved Working code in old database don't work in new one. (1 Viewer)

lodmark

Member
Local time
Today, 01:10
Joined
Jul 24, 2020
Messages
232
Hey!
I have created a new database for my vinyl collection, following tips I received from this forum.
So far, things are going well.
I have some code from the old database, that works with that database, I thought I would recycle that code.
It's about choosing a picture for the disc.
I have copied the code and renamed controls and database objects.
But I get an error that I do not understand, the error message says "Run-Time error '438': Object does not support this property or method".
As I said, the code works in the old database.
What is wrong.
This is the code for the "PicturePicker"

Code:
Public Function PicturePicker() As String
    Dim fd As Office.FileDialog
    Dim FileName As String
    
    'Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
    With fd
        .title = "Select a Picture"
        .Filters.Clear
        .Filters.Add "Pictures", "*.ani;*.bmp;*.gif;*.ico;*.jpe;*.jpeg;*.jpg;*.pcx;*.png;*.psd;*.tga;*.tif;*.tiff;*.webp;*.wmf, 1"
        .Filters.Add "All files", "*.*", 2
        .AllowMultiSelect = False
        If .Show = -1 Then
            PicturePicker = (.SelectedItems(1))
        End If
    'Set variable "filename" equal to path of file selected:
    FileName = fd.SelectedItems(1)
    'You can now use the filename for the file selected in your code:
    MsgBox FileName
    End With
    Set fd = Nothing
End Function

And this is for the click event that belongs to the button that selects the picture.

Code:
Private Sub cmdUpdateAlbumPicture_Click()
    Dim strPicture As String
    Dim ID As Long
    strPicture = PicturePicker
    'MsgBox strPicture
    If Len(strPicture) > 0 Then
        Me.AlbumPicture = strPicture
    End If
End Sub


This is where the error occurs, in the line:
Me.AlbumPicture = strPicture


As usual, I am grateful for all the tips.
The database is also attached, there is only rubbish in it so change as you want.

Leif
 

Attachments

  • NewthinkingRecordCollectionVersion2.zip
    103.6 KB · Views: 419

Gasman

Enthusiastic Amateur
Local time
Today, 00:10
Joined
Sep 21, 2011
Messages
14,286
You are not passing anything back from the function.?
I doubt that worked in the old DB as is ? :unsure:
 

lodmark

Member
Local time
Today, 01:10
Joined
Jul 24, 2020
Messages
232
You are not passing anything back from the function.?
I doubt that worked in the old DB as is ? :unsure:
Thanks @Gasman

The old database is attached.
The form is here called "Mina skivor" or frm_record2.
Test and you'll se that it works.
But I've may have missed something.
I've think you helped me in the past so you may recognize the database.

Leif
 

Attachments

  • Skivsamlingen.zip
    750 KB · Views: 352

Gasman

Enthusiastic Amateur
Local time
Today, 00:10
Joined
Sep 21, 2011
Messages
14,286
I cannot open it in 2007.
I suggest you look at the (what you call same code) in the old DB.

Alternatively add
Code:
PicturePicker = filename
as the last line in that function.

Again as always, WALK THROUGH THE CODE.
 

lodmark

Member
Local time
Today, 01:10
Joined
Jul 24, 2020
Messages
232
Hello @Gasman

I added the line.
Skärmklipp.JPG


Still the same error message.

This is the code from the old database.


Skärmklipp.JPG


I saved the two databases in 2003 version if you want to look at them.

Leif
 

Attachments

  • NewthinkingRecordCollectionVersion2.zip
    822.2 KB · Views: 438

lodmark

Member
Local time
Today, 01:10
Joined
Jul 24, 2020
Messages
232
I cannot open it in 2007.
I suggest you look at the (what you call same code) in the old DB.

Alternatively add
Code:
PicturePicker = filename
as the last line in that function.

Again as always, WALK THROUGH THE CODE.
I'm not that good at "walking through the code". Actually I don't understand it.
Have you any good groundly learning tip?

Leif
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:10
Joined
Sep 21, 2011
Messages
14,286
Yes just start. Seriously, if you do not understand it, why bother. You cannot expect people to write everything for you. You need to start for yourself. Everyone has to start somewhere.
In your left pic you have
PicturePicker = .selecteditems(1)
So that is what is returned from that function?
So the code in the new db is nothing like the old db😔

However, I must apologise now, I missed the PicturePicker inside the If construct, so it was passing something after all. My bad😠

Look at the debugging link in my signature.
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 00:10
Joined
Sep 21, 2011
Messages
14,286
Amazing, sometimes I have to debug to see the actual picture. Then it is easy.
This is why you need to start, to slowly develop your skills, just as I did.

The old code is
Code:
        Me.record_picture = strPicture
The new code was
Code:
        Me.AlbumPicture = strPicture
that should be
Code:
        Me.AlbumPicture.Picture = strPicture

Having the picture in the control name, threw me on initial glance.
However I now have NO idea as to why the old code works, and I did test it? :(

Anyway, that is the fix you need here for this latest query.
Again, my apologies for leading you astray with that initial line.

Edit:
OK, I have found out why. In the old DB you set the control source for the control, which is called record_picture, not the Picture property of the control.

So again, code nothing like the old DB, compounded by the fact, you do not know what the code is doing, and amending it, causing more problems.
This is just a recipe for disaster, time and time again.
Pick a method and stick to it. Same with naming conventions.
 
Last edited:

lodmark

Member
Local time
Today, 01:10
Joined
Jul 24, 2020
Messages
232
Thanks @Gasman
I do understand a bit of the code, but not so much to search for faults.

A little problems with the English language too.

Thanks a lot!

Now I will build a code to update the table........wonder how? :LOL:

And I will look at your link :)

Leif
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:10
Joined
Sep 21, 2011
Messages
14,286
I have edited my last reply, so please re read it.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:10
Joined
Oct 29, 2018
Messages
21,469
See if this work for you.
 

Attachments

  • NewthinkingRecordCollectionVersion2.zip
    93.8 KB · Views: 413

Users who are viewing this thread

Top Bottom