Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid From 1

Status
Not open for further replies.

PrimoSteve

Technical User
Aug 11, 2021
25
IE
Hello All,

I have a subform that acts like a grid that displays 24 command button ( 4 Rows and 6 columns)

tblCmds
cmdID Short Text
cmdCaption Short Text
cmdPhotoUrl Short Text


Private Sub Form_Load()
On Error GoTo FormLoadErr:

Dim ctl As Control
Me.cTemp.SetFocus


For Each ctl In Me.Controls

If TypeOf ctl Is CommandButton Then

If ctl.Name Like "cmdOrder*" Then

ctl.Visible = True
ctl.Caption = DLookup("[cmdCaption]", "tblCmds", "[cmdID]='" & ctl.Name & "'")
If ctl.Caption = "Empty" Then ctl.Visible = False

End If

End If

Next ctl

DoCmd.Save

Exit Sub

FormLoadErr:
MsgBox ctl.Name & "-" & err.Description

End Sub


The following code above works fine to display the caption but when I add the following line of code to display the picture.

ctl.Picture = DLookup("[cmdPhotoUrl]", "tblCmds", "[cmdID]='" & ctl.Name & "'")

I get this error

"cmdOrder02-SampleDB can't open tje file
'C:\Users\Admin\Documents\Parts1.png'."

Any assistance would help in writing this code the correct way



For Each ctl In Me.Controls

If TypeOf ctl Is CommandButton Then

If ctl.Name Like "cmdOrder*" Then

ctl.Visible = True
ctl.Caption = DLookup("[cmdCaption]", "tblCmds", "[cmdID]='" & ctl.Name & "'")
ctl.Picture = DLookup("[cmdPhotoUrl]", "tblCmds", "[cmdID]='" & ctl.Name & "'")
If ctl.Caption = "Empty" Then ctl.Visible = False

End If

End If

Next ctl

DoCmd.Save


Regards
Primo
 
And I would move this one line for Caption outside the If-Then-Else:

Code:
If ctl.Name Like "cmdOrder*" Then
    ctl.Visible = True
    ctl.Caption = DLookup("[cmdCaption]", "tblCmds", "[cmdID]='" & ctl.Name & "'")
    pic = DLookup("[PhotoURL]", "tblCmds", "[cmdID]='" & ctl.Name & "'")
    
    If IsNull(pic) Or pic & "" = "" Then
        MsgBox " No Image Available"
    Else
        ctl.Picture = pic
        'If ctl.Caption = "Empty" Then ctl.Visible = False
    End If
    If ctl.Caption = "Empty" Then ctl.Visible = False
End If
 
That did the trick! Thanks for your help
Much appreciated,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top