Data in form combobox needs to retrieve data as read only (1 Viewer)

simonwait

New member
Local time
Today, 09:19
Joined
Jul 29, 2019
Messages
2
Hi

Although I do quite a bit in VB6 and VBA in Excel, Access has always been harder for me to grasp so I'm here as a newbie looking for some help!

I have a form which I would like to use a drop-down list of players in a football team. On selection, the form should populate a few text boxes and then buttons on the form are used to generate pdfs, etc of information about the player.

This all works great but i find that when i look at my data, players are having their data overwritten with other players info! I assume this is because it is being updated when i select a new player.

I tried playing with the allow edit, allow addition etc parameters for the form but then reached a point where nothing happened on the dropdown event.

The event actually triggers some VBA (which may actually be the wrong thing to do but given my background that where i headed!).

Code:
  Me.PlayerName = DLookup("PlayerName", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.DOB = DLookup("DOB", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Address = DLookup("Address", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.School = DLookup("School", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent1Name = DLookup("Parent1Name", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent1Email = DLookup("Parent1Email", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent1Phone = DLookup("Parent1Phone", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent2Name = DLookup("Parent2Name", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent2Email = DLookup("Parent2Email", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    Me.Parent2Phone = DLookup("Parent2Phone", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")
    'Me.Photo.Picture = DLookup("Photo", "ActivePlayers", "ActivePlayers.PlayerName='" & Me.Player.Value & "'")
    Me.Whatsapp = DLookup("WhatsappGroup", "ActivePlayers", "ActivePlayers.PlayerName=""" & Me.Player.Value & """")

Ultimately I would like to be able to change the data via the form but maybe only by changing the data and then clicking a save button. By default i want this to act more as a read-only form.

I hope my ramblings make sense. Many thanks in advance
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:19
Joined
Feb 19, 2013
Messages
16,553
looks like you are going about this in completely the wrong way. You should bind your form to activeplayers then in the combo after update event apply a filter. You should also have a primary key - what if you have two players with the same name?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:19
Joined
May 7, 2009
Messages
19,170
if u make those textboxes Unbound, no control source, it will not be overwritten.
 

simonwait

New member
Local time
Today, 09:19
Joined
Jul 29, 2019
Messages
2
Hi, sorry I couldn't find the thread for a while. Thank you both for your help. I actually used arnelgp's solution but agree with CJ_London's comments regarding the primary key - there is one in the table but wasn't utilizing that in the form so I am now.
 

Users who are viewing this thread

Top Bottom