Combo Box and DoCmd.GoToRecord

P Zero

Registered User.
Local time
Today, 22:37
Joined
Mar 15, 2006
Messages
41
I'm putting together a database to store my client and billing details and for generating invoices.

I have a form for viewing clients called 'frmClients' and on the form I have a combo box called 'comboClientName'. This is how it should work;

The form is opened and it displays the first record.
The field 'ClientName' should be displayed for the current record in the combo box.
To go to another record, the combo box should be used to choose the client name.

I'm having difficulty putting together the code for the combo box though. I know it should be an 'AfterUpdate' event and the DoCmd.GoToRecord action should be used, but how to it all to work properly?
 
I've done this before, and if I remember right, you need to change your combo box to 2 columns, Hide the first. The first should be the record number, the second would be what you want it to display. (Client name).

Now, after update, enter code docmd.findrecord yourcombo.value, which should now be the record number.

This is off the top of my head, so you may need to fill in the blanks, but it should give you a starting point.
 
I think this is right
 
Thanks, my combo box has the two columns, ClientID and ClientName. My code is as follows;

Code:
Private Sub comboClientName_AfterUpdate()
On Error GoTo Err_comboClientName_AfterUpdate
    
    DoCmd.FindRecord comboClientName.Value

Exit_comboClientName_AfterUpdate:
    Exit Sub

Err_comboClientName_AfterUpdate:
    MsgBox Err.Description
    Resume Exit_comboClientName_AfterUpdate
    
End Sub

But I get this message pop up when it tries to run;

'A macro set to one of the current field's properties failed because of an error in the FindRecord action argument.'

What have I done wrong?
 
Ah yes,

Forgot to mention. Add a field for client ID. (Mine is hidden)

before your code unhide it, and set focus.

me.clientid.visible = true
me.clientid.setfocus

then your find code after this. (don't forgot to hide it again afterwards if that's what you want to do)
 
Thats got it. Thanks very much, it works great :)
 
Following on from this topic;

When I open the form 'frmClients', the first record is displayed, however the combo box 'comboClientName' is empty. How can I get the combo box to display the Client Name in this situation?
 

Users who are viewing this thread

Back
Top Bottom