473,396 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Display Record on Form based on value in Text box

13
Good day all,

Using Access 2007 but DB is created in Access 200o format so I can still use User Level security.

I have what am sure is a very newbie question. I want to add a control to a form which allows the user to type in a value, in this case a site #, and have the form navigate to the corresponding record.

I found some sample code that does this using a Combo Box. I tried modifying this code to use an unbound Text Box but I keep getting a runtime error 13 Type Mismatch Error.

Rec_Num is a Text Field.

Form is a Single Form.

Here is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFindSite_AfterUpdate()
  2.  
  3. Dim rs As Object
  4.  
  5.     Set rs = Me.Recordset.Clone
  6.     rs.FindFirst "[Rec_Num] = " & Str(Nz(Me![txtFindSite], 0))
  7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8.  
  9. End Sub
If you guys need more info just let me know. Thanks in advance for any help.

Regards,
Garrett
Feb 19 '08 #1
10 10649
ADezii
8,834 Expert 8TB
Good day all,

Using Access 2007 but DB is created in Access 200o format so I can still use User Level security.

I have what am sure is a very newbie question. I want to add a control to a form which allows the user to type in a value, in this case a site #, and have the form navigate to the corresponding record.

I found some sample code that does this using a Combo Box. I tried modifying this code to use an unbound Text Box but I keep getting a runtime error 13 Type Mismatch Error.

Rec_Num is a Text Field.

Form is a Single Form.

Here is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFindSite_AfterUpdate()
  2.  
  3. Dim rs As Object
  4.  
  5.     Set rs = Me.Recordset.Clone
  6.     rs.FindFirst "[Rec_Num] = " & Str(Nz(Me![txtFindSite], 0))
  7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8.  
  9. End Sub
If you guys need more info just let me know. Thanks in advance for any help.

Regards,
Garrett
In the AfterUpdate() Event of txtFindSite:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFindSite_AfterUpdate()
  2. Dim rs As DAO.Recordset
  3.  
  4. If Not IsNull(Me![txtFindSite]) Then
  5.   Set rs = Me.RecordsetClone
  6.   rs.FindFirst "[Rec_Num] = '" & Me![txtFindSite] & "'"
  7.   If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8. Else
  9.   Exit Sub
  10. End If
  11. End Sub
Feb 19 '08 #2
maxx429
13
In the AfterUpdate() Event of txtFindSite:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFindSite_AfterUpdate()
  2. Dim rs As DAO.Recordset
  3.  
  4. If Not IsNull(Me![txtFindSite]) Then
  5.   Set rs = Me.RecordsetClone
  6.   rs.FindFirst "[Rec_Num] = '" & Me![txtFindSite] & "'"
  7.   If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8. Else
  9.   Exit Sub
  10. End If
  11. End Sub
Thank you for the tip. This fixes the runtime error, but the form does not navigate to the Site # that's keyed into the text box.

This probably seems trivial. I'm only doing this due to user preference. Most of mine prefer to key in Sites from memory rather than scroll through the list in a Combo Box.

Does the Text Box need to be on a particular part of the Form? It is currently on the Form Header.
Feb 19 '08 #3
ADezii
8,834 Expert 8TB
Thank you for the tip. This fixes the runtime error, but the form does not navigate to the Site # that's keyed into the text box.

This probably seems trivial. I'm only doing this due to user preference. Most of mine prefer to key in Sites from memory rather than scroll through the list in a Combo Box.

Does the Text Box need to be on a particular part of the Form? It is currently on the Form Header.
Does the Text Box need to be on a particular part of the Form?
No, it can be anywhere on the Form.

form does not navigate to the Site # that's keyed into the text box.
Which Field are you trying to Navigate to, [Rec_Num] as indicated in your code, or [Site #]?
Feb 20 '08 #4
maxx429
13
No, it can be anywhere on the Form.


Which Field are you trying to Navigate to, [Rec_Num] as indicated in your code, or [Site #]?
Sorry for the confusion. Sometimes I'm dumber than I give myself credit. :)

Rec_Num is the Primary Key for the table on which my Form is based. I can see now that the Combo Box code I am modifying for use with the Text Box is finding the first Rec_Num in the table that is associated with whatever Site # is chosen in the Combo Box.

That explains why the Text Box code isn't working, because it's being given a Site # and trying to match it to a value in the Rec_Num field.

This presents me with a new issue. It is possible for a Site # to appear more than once in the table. Hence the use of Rec_Num as a Primary Key. Rec_Num is an Auto_Number field.

It seems as if, in order to look up a unique record via an unbound Text Box control, I may have to come up with a unique but intuitive way of identifying which instance of Site # I want to find. A Site may be visited several times, the difference being which project it is associated with at a given time.

So, maybe two unbound Text Boxes, one for Site # and one for Project name? Does that sound reasonable to the more seasoned folks around here?

Thanks again for any assistance. This is great site and has been a tremendous help.

Garrett
Feb 20 '08 #5
NeoPa
32,556 Expert Mod 16PB
If there are many jobs per site then that sounds good.
If it's rare (but not impossible) for a site to have multiple jobs then I'd consider keeping it as it is, but checking the table with the AfterUpdate code for multiples. If any exist, THEN pop up a form selecting the jobs from those that match the site.
Feb 20 '08 #6
maxx429
13
If there are many jobs per site then that sounds good.
If it's rare (but not impossible) for a site to have multiple jobs then I'd consider keeping it as it is, but checking the table with the AfterUpdate code for multiples. If any exist, THEN pop up a form selecting the jobs from those that match the site.
Yeah, a Site may occur numerous times, but only once per Project, so a multi-box filter sounds like the way to go.

Out of curiosity, how would one go about determining if multiple records resulted from a filter, using VBA? I probably won't need to use it now, but I can envision other applications for that capability.

Thanks for the pointers. :)

Garrett
Feb 20 '08 #7
NeoPa
32,556 Expert Mod 16PB
...
Out of curiosity, how would one go about determining if multiple records resulted from a filter, using VBA? I probably won't need to use it now, but I can envision other applications for that capability.
...
You would use the Count() function within SQL or DCount() within VBA. There's also the facility to handle the On No Data event of a Report.
Feb 20 '08 #8
ADezii
8,834 Expert 8TB
Sorry for the confusion. Sometimes I'm dumber than I give myself credit. :)

Rec_Num is the Primary Key for the table on which my Form is based. I can see now that the Combo Box code I am modifying for use with the Text Box is finding the first Rec_Num in the table that is associated with whatever Site # is chosen in the Combo Box.

That explains why the Text Box code isn't working, because it's being given a Site # and trying to match it to a value in the Rec_Num field.

This presents me with a new issue. It is possible for a Site # to appear more than once in the table. Hence the use of Rec_Num as a Primary Key. Rec_Num is an Auto_Number field.

It seems as if, in order to look up a unique record via an unbound Text Box control, I may have to come up with a unique but intuitive way of identifying which instance of Site # I want to find. A Site may be visited several times, the difference being which project it is associated with at a given time.

So, maybe two unbound Text Boxes, one for Site # and one for Project name? Does that sound reasonable to the more seasoned folks around here?

Thanks again for any assistance. This is great site and has been a tremendous help.

Garrett
So, maybe two unbound Text Boxes, one for Site # and one for Project name? Does that sound reasonable to the more seasoned folks around here?
What you are referring to is called a Composite Primary Key, and is the combination of 2 or more Fields, which defined together as a single Primary Key, will make each Record Unique. It is a perfectly acceptable practice, and if the combination of [Site #] and [Project Number] produce a Unique combination, they can be used as a Primary Key. Be advised that a search for a Unique Record may now involve multiple criteria ([Site #] and [Project Name]).
Feb 21 '08 #9
maxx429
13
What you are referring to is called a Composite Primary Key, and is the combination of 2 or more Fields, which defined together as a single Primary Key, will make each Record Unique. It is a perfectly acceptable practice, and if the combination of [Site #] and [Project Number] produce a Unique combination, they can be used as a Primary Key. Be advised that a search for a Unique Record may now involve multiple criteria ([Site #] and [Project Name]).
I'm familiar with the concept of a Composite Primary Key. I was actually intending to set up my table that way. However, I was also looking for a way to track changes to records and came across some pre-made code by a gent named Allen Browne to create an Audit Trail. His code required that the table being tracked have an Auto Number field as the Primary Key, so I modified my table accordingly. I'm not yet savvy enough in VBA to modify his code to use my original Composite Key setup. I'm still struggling to find a way to modify his code to only track changes if certain fields on a Form are changed, as opposed to how it works now where a complete before and after copy of the record is recorded if anything on the form changes. If anyone has some good advice on that, I'd be forever grateful. :)

Regards,
Garrett
Feb 21 '08 #10
ADezii
8,834 Expert 8TB
I'm familiar with the concept of a Composite Primary Key. I was actually intending to set up my table that way. However, I was also looking for a way to track changes to records and came across some pre-made code by a gent named Allen Browne to create an Audit Trail. His code required that the table being tracked have an Auto Number field as the Primary Key, so I modified my table accordingly. I'm not yet savvy enough in VBA to modify his code to use my original Composite Key setup. I'm still struggling to find a way to modify his code to only track changes if certain fields on a Form are changed, as opposed to how it works now where a complete before and after copy of the record is recorded if anything on the form changes. If anyone has some good advice on that, I'd be forever grateful. :)

Regards,
Garrett
FYI, you can create a Unique Index on multiple Fields without it being the Primary Key, your Primary Key would be maintained independently of the Unique Index.
Feb 21 '08 #11

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

Similar topics

19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
3
by: Steven Stewart | last post by:
Hi there, I have posted about this before, but yet to arrive at a solution. I am going to try to explain this better. I have an Employees table and a Datarecords table (one-to-many...
0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
2
by: Corepaul | last post by:
As input is typed into a text box, I would like to search a recordset for the first record that matches what has been typed so far. I would like to update the text box to display the letters typed...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
3
by: Bob Sanderson | last post by:
I am trying to create a form for a MySQL database similar to a spreadsheet. The idea is to display a list of records, with the last line of the list being an input form. When the user enters data...
36
by: beebelbrox | last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code. WIndows OS MSaccess 2003 This code is attached to an unbound form that will display a specific recordset...
2
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.