List box selection - opening a form (1 Viewer)

JamesWB

Registered User.
Local time
Today, 11:55
Joined
Jul 14, 2014
Messages
70
Morning all. :)

I have a list box, List3, in a form, which is populated from a query. The list populates correctly.

I added a command button which I want to open a new edit form with the selected record from the List3 control.

I used this code on the DoubleClick event - it opens the form EditEquipment, but the form does not have the relevant record, ItemID, open in it. It's an autonumber field and primary key. Is there something I now need to do in the EditEquipment OnLoad event or something like that?

Private Sub Command5_DblClick(Cancel As Integer)
If Len(Me.List3 & "") > 0 Then
DoCmd.OpenForm "EditEquipment", acNormal, , _
"[ItemID] = '" & Me.List3 & "'"
End If
End Sub

Thanks for any tips. :)
 

JHB

Have been here a while
Local time
Today, 12:55
Joined
Jun 17, 2012
Messages
7,732
Is the fieldtype for ItemID text or number?
If number then :
Code:
"[ItemID] = " & Me.List3
 

JamesWB

Registered User.
Local time
Today, 11:55
Joined
Jul 14, 2014
Messages
70
Is the fieldtype for ItemID text or number?
If number then :
Code:
"[ItemID] = " & Me.List3

Ah - good point. I've changed it, it was an autonumber type.

Nothing has changed unfortunately though - the form opens with no error, but no record is showing.

The only code I have at the moment in the destination form is a do.command maximise.

The record controls below show it on 'record 1 of 1' but the field boxes are all blank.
 

JHB

Have been here a while
Local time
Today, 12:55
Joined
Jun 17, 2012
Messages
7,732
Is the form's property "Data Entry" set to "No"?
 

JackKaptijn

Registered User.
Local time
Today, 12:55
Joined
Dec 10, 2012
Messages
38
Made a test. See included database.
Test is by ID which is an autonumber field.
Als by ItemID which is an text field.

Both work fine. Mayby this helps you.....
 

Attachments

  • Test.accdb
    672 KB · Views: 88

JamesWB

Registered User.
Local time
Today, 11:55
Joined
Jul 14, 2014
Messages
70
Further to this, I just built a really simple test form which only has the ItemID plus another field and tried the same code with that and it works fine.

I presume some property setting in my complicated big form is blocking it from opening with the correct ItemID selected. Any ideas which property this might be please? I've been down all the obvious ones and they seem to have no effect....
 

JamesWB

Registered User.
Local time
Today, 11:55
Joined
Jul 14, 2014
Messages
70
Is the form's property "Data Entry" set to "No"?

Set to "Yes". :)

These are the Data properties from EditEquipment.

Record Source EquipmentDetails
Recordset Type Dynaset
Fetch Defaults Yes
Filter (blank)
Filter On Load No
Order By (blank)
Order By On Load Yes
Wait for Post Processing No
Data Entry Yes
Allow Additions Yes
Allow Deletions No
Allow Edits Yes
Allow Filters Yes
Record Locks No Locks
 

JamesWB

Registered User.
Local time
Today, 11:55
Joined
Jul 14, 2014
Messages
70
Made a test. See included database.
Test is by ID which is an autonumber field.
Als by ItemID which is an text field.

Both work fine. Mayby this helps you.....

Thanks for your efforts, really appreciated. :D

I tried the same thing and it works fine, so yes, the basic macro code is fine.

Evidently the problem is some property or other on the form.

I have some macro code already running on the target form that does things like making some fields inoperative until you select a particular combo box option - might that be affecting this?
 

JHB

Have been here a while
Local time
Today, 12:55
Joined
Jun 17, 2012
Messages
7,732
You're welcome - luck with your project! :)
 

Users who are viewing this thread

Top Bottom