Populating Search Text Box

access7

Registered User.
Local time
Today, 23:01
Joined
Mar 15, 2011
Messages
172
Hello All... wondered if anyone could give me some advice on the best way to do the following... (see attached db)

Ref: Frm_Search

I am trying to put an error message in place so that a user cannot click the OK button without first having either typed a company name in the text box (txtSearch) or picked one from the list...

The way I was considering doing this was to write some code on the on_click event of the OK button along the lines of 'If txtSearch = Null then MsgBox = 'You must choose a company' (or something to that effect)

To make this work I believe I am going to need something which when a user clicks on one of the companies in the listbox it autopopulates the text box above with that companies name... ?? :confused:
The list box is populated from a query (Qry_SearchProspect / Qry_SearchClient)

Unless anyone else has any other ideas - all are very welcome :)
 

Attachments

Hi..

Two different proposals..:

This is the you want..:

Code:
Private Sub CmdOK_Click()

If ListCompany.ListCount - 1 <= 0 Then
MsgBox "You must choose a company.."
Else
Call OpenCompanyForm
End If

End Sub

This a different approach..: ;)

Code:
Private Sub txtSearch_Change()

Me.ListCompany.Requery

If ListCompany.ListCount - 1 <= 0 Then
CmdOK.Enabled = False
Else
CmdOK.Enabled = True
End If

End Sub
 
Hello
Thanks for your response; I like the idea and am just trying the first approach however it appears to be skipping straight over the error message and going straight to the 'else' statement... please could you clarify for me what exactly the '- 1 <=0' means so I can work out whats going on. At the moment it seems to be taking the number of companies on the list and adding one (when I step through it in the VBA window)...?
Many Thanks again for your help, much appreciated! :-)
 
I understood your question mistake :(


The first proposal, I have looked at the list record.
If you have, we have opened the form..

but I think you want..:

if from the list recording not chosen, form is not opened..


Code:
Private Sub CmdOK_Click()
Dim i, trz As Integer

For i = 1 To ListCompany.ListCount - 1
    If ListCompany.Selected(i) = True _
       Then trz = Nz(trz, 0) + 1
Next

If trz = 0 Then
    MsgBox "You must choose a company.."
    Else
    Call OpenCompanyForm
End If

End Sub

I hope you could help.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom