By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,471 Members | 2,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,471 IT Pros & Developers. It's quick & easy.

OnClick Event coding

Stang02GT
Expert 100+
P: 1,208
Can anyone help me out with some VBA coding.


I would like to have two text boxes where the user can enter a number in either of the boxes and click a search button to bring up the record.

Example of this is:

VIN num SEARCH
Model num

User can enter a VIN or model number depending on which one they have. ***These are not the feilds im using just examples****


I need help with the OnClick event coding
Jun 14 '07 #1
Share this Question
Share on Google+
12 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Please remember to provide a meaningful Title for any threads started (Please Use Appropriate Titles for New Threads!). This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR.
Jun 15 '07 #2

P: 24
Can anyone help me out with some VBA coding.


I would like to have two text boxes where the user can enter a number in either of the boxes and click a search button to bring up the record.

Example of this is:

VIN num SEARCH
Model num

User can enter a VIN or model number depending on which one they have. ***These are not the feilds im using just examples****


I need help with the OnClick event coding

what exactly is the problem with the onclick event coding?
Jun 15 '07 #3

JKing
Expert 100+
P: 1,206
If I have this right you want to prompt the user for two values and then clicking the search button bring up a form displaying the record specific to those values.

Let's assume the two values we are working with are modelID and yearID and they are text data types.
The corresponding text boxes are txtModelID and txtYearID.
The form for the record will be frmDisplayRecord.

The values from the textboxes will be used to build the WHERE statement of the open form command. Once built we just pass the string in as a parameter along with the name of the form we want to open.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.  
  3. Dim strLinkCriteria As String
  4.  
  5. strLinkCriteria = "modelID = '" & Me.txtModelID & "' AND yearID = '" & Me.txtYearID & "'"
  6.  
  7. Docmd.OpenForm "frmDisplayRecord", acNormal,, strLinkCriteria
  8.  
  9. End Sub
  10.  
If the values are not text remove the single quotes.

If this is not what you're trying to do please repost your question in more detail otherwise good luck and I hope this helped.
Jun 16 '07 #4

Stang02GT
Expert 100+
P: 1,208
I think to simplify this situation I'd like to just focus on getting a simple search to work.

The users do not like the combo box search for whatever reasons, so the would like to see a text box ( where they may enter there criteria) and a "Search Button" to execute the search.

I'll try to explain this and not confuse you :)

I have a four tables and all data in the tables has a TC NUM (Primary Key). I have forms for each table ( based on user request, because each table relates to a different area of the company) to search/update/delete...etc.

The users would like to search by TC NUM. But they would like to have it in the form of a txt box with a "Search BUtton".

I hope this helps, and thank you for trying to help me!!!















If I have this right you want to prompt the user for two values and then clicking the search button bring up a form displaying the record specific to those values.

Let's assume the two values we are working with are modelID and yearID and they are text data types.
The corresponding text boxes are txtModelID and txtYearID.
The form for the record will be frmDisplayRecord.

The values from the textboxes will be used to build the WHERE statement of the open form command. Once built we just pass the string in as a parameter along with the name of the form we want to open.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.  
  3. Dim strLinkCriteria As String
  4.  
  5. strLinkCriteria = "modelID = '" & Me.txtModelID & "' AND yearID = '" & Me.txtYearID & "'"
  6.  
  7. Docmd.OpenForm "frmDisplayRecord", acNormal,, strLinkCriteria
  8.  
  9. End Sub
  10.  
If the values are not text remove the single quotes.

If this is not what you're trying to do please repost your question in more detail otherwise good luck and I hope this helped.
Jun 18 '07 #5

JKing
Expert 100+
P: 1,206
How are you displaying search results to the user? Are you using a subform, report, seperate form or do you just want the current form to flip to that record?
Jun 18 '07 #6

Stang02GT
Expert 100+
P: 1,208
How are you displaying search results to the user? Are you using a subform, report, seperate form or do you just want the current form to flip to that record?


I have to current form bringing up that record. I have Text Boxes for each feild and when a search is completed the data is brought up in the respective feild.
Jun 18 '07 #7

JKing
Expert 100+
P: 1,206
Alright. You can try setting the form's filter property and then turning the filter on when the user clicks the search button.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2. Me.Filter = "TCNUM = " & txtSearchValue
  3. Me.FilterOn = True
  4. End Sub
  5.  
TCNUM would be the key you want to search by and txtSearchValue is the textbox the user is inputting the search value into.

If the key you are searching by is a text data type then you would alter the 2nd line by enclosing the textbox value in single quotes:
Expand|Select|Wrap|Line Numbers
  1. Me.Fiilter = "TCNUM = '" & txtSearchValue & "'"
  2.  
Let me know how this works out.

JKing
Jun 18 '07 #8

Stang02GT
Expert 100+
P: 1,208
Alright. You can try setting the form's filter property and then turning the filter on when the user clicks the search button.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2. Me.Filter = "TCNUM = " & txtSearchValue
  3. Me.FilterOn = True
  4. End Sub
  5.  
TCNUM would be the key you want to search by and txtSearchValue is the textbox the user is inputting the search value into.

If the key you are searching by is a text data type then you would alter the 2nd line by enclosing the textbox value in single quotes:
Expand|Select|Wrap|Line Numbers
  1. Me.Fiilter = "TCNUM = '" & txtSearchValue & "'"
  2.  
Let me know how this works out.

JKing



Unfortunatly i am getting an error message

RUN TIME ERROR '2448'

YOU CAN"T ASSIGN A VALUE TO THIS OBJECT
Jun 18 '07 #9

JKing
Expert 100+
P: 1,206
Are you using the textbox you display your TCNUM in to act as your search textbox as well?

Is there a space in the field name that you are passing to the Me.Filter = ?
Example: Me.Filter = "Model Number = "

In this case you need to add [] around the field
Me.Filter = "[Model Number] = "
Jun 18 '07 #10

Stang02GT
Expert 100+
P: 1,208
Are you using the textbox you display your TCNUM in to act as your search textbox as well?

Is there a space in the field name that you are passing to the Me.Filter = ?
Example: Me.Filter = "Model Number = "

In this case you need to add [] around the field
Me.Filter = "[Model Number] = "

No i have a seperate box in the hearder where the search button/box is
Jun 18 '07 #11

JKing
Expert 100+
P: 1,206
I made a quick edit there did you see the second possibility?

And if it isnot that could you paste me the snippet of your code.
Jun 18 '07 #12

Stang02GT
Expert 100+
P: 1,208
I made a quick edit there did you see the second possibility?

And if it isnot that could you paste me the snippet of your code.
Good news i was able to complete this task here is the code....

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command35_Click()
  2. If IsNull(Text15) = False Then
  3.         Me.Recordset.FindFirst "[TC Num]=" & Text15
  4.         End If
  5. End Sub
Jun 19 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.