Getting values from text boxes

seanog2001

Registered User.
Local time
Today, 10:18
Joined
Jun 26, 2006
Messages
67
Im running some VB code when you click the cmdSearch button on a form
the code is pretty basic but i need to take values in from my Supervisor and Months combo boxes on the form how do i write the code to take these values from the form so VB knows what they are.
 
Need more info. Sounds like you need a couple of variables that are filled when some event takes place.
 
TedMartin said:
Need more info. Sounds like you need a couple of variables that are filled when some event takes place.


here is what i need to do

If comboboxSupervisor = "whatever the user picks" and comboboxMonths = "whatever month user picks" then

we look up a query which finds the supervisor and the month and returns the relevant info from the table.

End if
 
Try something like this. It should work. Be VERY careful with the ' and " syntax. It is " [Field] = ' " & strvariable & " ' " without all the spaces.

You will need to make the three string variables, don't forget to Dim them as String, with the value from the combo boxes but that could be done through the On Lost Focus event or before the actual command event that calls the query, just setfocus on each of the individual combo boxes and make the string variable equal to the combo box value/text.

Then ...

myString = "[SupervisorField] = '" & strSupervisor & "' And [MonthField] = '" & strMonth & "'"

DoCmd.OpenQuery "QueryName", acNormal, "", myString
OR
DoCmd.OpenForm "FormName", acNormal, "", myString


Do you need a routine for a No Match as it may error if this is the case? Just manage the error through the usual On Error sequence and the if Err.Number = xx then etc.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom