473,405 Members | 2,338 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,405 software developers and data experts.

Updating a Table from a form

I have form in access what I am trying to do is search by a specific field and fill in most of the filed based on the search. Then update some other fields in that records based on the information that was populated from the exiting table.

I have an unbouded field called txtSearch. I want it to search the table in a field called [Appointment]. Once it locates the appointment field I want it to populate the other field in my form.

I have the following code but it errors out at [code] "Me.RecordsetClone.MoveFirst" [code]


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Private Sub cmdSearch_Click()
  4. Dim bkmk As Variant
  5. Dim strField As String
  6. Me.RecordsetClone.MoveFirst
  7. 'Find the first record that matches what
  8. 'is in the search text box.
  9. Me.RecordsetClone.FindFirst "Appointment Like " _
  10. & Chr(34) & Me.txtSearch & "*" & Chr(34)
  11.  
  12. If Me.RecordsetClone.NoMatch Then
  13. MsgBox "No Match"
  14. Else
  15. bkmk = Me.RecordsetClone.Bookmark
  16. Me.Recordset.Bookmark = bkmk
  17. End If
  18. End Sub
  19.  
  20.  
  21.  
  22. Private Sub Form_Load()
  23. DoCmd.GoToRecord , "", acNewRec
  24. End Sub
  25.  
  26.  
  27. Private Sub Save_Driver_Info_Click()
  28. RetValue = MsgBox("Entry Saved. Thank you", vbOK)
  29. DoCmd.GoToRecord , "", acNewRec
  30. End Sub
  31.  
  32.  
  33.  
It works perfectly find when I use it with another table.
Attached Files
File Type: docx Access Run-time Error.docx (444.4 KB, 289 views)
Mar 3 '15 #1
6 1182
twinnyfo
3,653 Expert Mod 2GB
Darcjohnson01,

My initial thought on your error is that your form is not bound to any table, which results in your error, because there is no error for the Recordset to move to.

It is also better programming to declare a Variable to hold your recordsetclone and then navigate within that recordset:

Expand|Select|Wrap|Line Numbers
  1. Dim rstClone as DAO.Recordset
  2. Set rstClone = Me.RecordsetClone
  3. If Not rstClone.RecordCount = 0 Then
  4.     With rstClone
  5.         .MoveLast
  6.         .MoveFirst
  7.     End With
  8. End If
Of course, the above code doesn't "do" anything, but is merely provided as an example.

Additionally, in your Search (lines 9-10), you are better off using syntax like this:

Expand|Select|Wrap|Line Numbers
  1. Me.RecordsetClone.FindFirst "Appointment Like '" & _
  2.     Me.txtSearch & "*'"
Although a String is delimited by Double Quotes ("Text"), when using strings within your search criteria, as you have in your example, the single quotes are required.

Hope this hepps!
Mar 3 '15 #2
I thank you for taking the time out to respond. It is connected a table. This same code works well in another table search without a problem. I am not sure if it is the field name or something specific to the field. I also appreciate your comment about the syntax. I do hope to see other response.
Mar 4 '15 #3
twinnyfo
3,653 Expert Mod 2GB
Have you tried this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.     Dim rstClone As DAO.Recordset
  3.     Dim strSearch As String
  4.  
  5.     strSearch = "Appointment Like '" & Me.txtSearch & "*'"
  6.     Set rstClone = Me.RecordsetClone
  7.     rstClone.FindFirst strSearch
  8.  
  9.     If rstClone.NoMatch Then
  10.         MsgBox "No Match"
  11.     Else
  12.         Me.Recordset.Bookmark = rstClone.Bookmark
  13.     End If
  14. End Sub
There is no need to Go to the first record, as the code will automatically find the first record that matches. This code works perfectly for me.
Mar 4 '15 #4
Brilstern
208 100+
twinnyfo,

Would it benefit the function at all by using this?
Expand|Select|Wrap|Line Numbers
  1. Me.txtSearch.Value
  2. 'vs
  3. Me.txtSearch
Mar 6 '15 #5
twinnyfo
3,653 Expert Mod 2GB
@Stevan,

In VBA, the default property of a Control is ".Value", so in one sense, it is redundant. It also cuts down on the number of keystrokes, but sometimes it does not hurt to be explicit.

The only exception I have found is when using the TempVars() variables. When one assigns a value to the TempVars() variables using a control on a Form, one must explicitly use the .Value property or else (for whatever reason) the TempVars variable thinks you are trying to assign the Object itself to the variable, vice just assigning the variable (which is counter to every other usage within VBA.

Example:

Expand|Select|Wrap|Line Numbers
  1. TempVars("StringName") = Me.txtString
  2.     'MS Access want to assign the Control itself to TempVars("StringName")
  3.  
  4. vs.
  5.  
  6. TempVars("StringName") = Me.txtString.Value
  7.     'MS Access will assign the value of txtString
Hope this clarifies.
Mar 6 '15 #6
Brilstern
208 100+
It does indeed. Thanks for the clarification twinnyfo!
Mar 6 '15 #7

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

Similar topics

1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
6
by: cyoung311 | last post by:
I'm trying to do an automatic update of one table from another through a form. Basically, when a selection is made for an item, in this case a particular workshop, I want to get the associated...
0
by: (PeteCresswell) | last post by:
I'm pretty far into a solution using MS Graph - i.e. it's too late to change now... - but from what little I've been able to find, using a Pivot-Table form sounds like the latest-and-greatest way...
1
by: abc my vclass | last post by:
Is VS2005 debugger let me to see dataset, datatable data as table form? I found if I watch some table or dataset variable is very very hard to see. Is there any good tools or add-ins for debugger...
2
by: StellaUK | last post by:
Hi I Need Help Or Should I Say Ideas Or General Pointers For The Best Way To Approach Designing My Table / Form. Im Wanting To Monitor Holidays In My Office An Employee Requests A Holiday...
2
by: rpjd | last post by:
I am trying to submit entries in a form to a database. I am using " within my submission form and $_POST I am getting the connection to the database but I my script is not executing,...
4
by: AlexNunley | last post by:
I've adopted a moderately sized (65k records) active use database (Access 2000, Windows XP). One of the most commonly used forms is whats called the RMA generation field, used to add claim...
4
by: Light1 | last post by:
I am working in Access 2003. I have a form that pulls information from a couple of tables. When the user chooses a selection from the dropdown menu of a combo box, it is putting that information...
0
by: Kori | last post by:
HI, I have a pivot table form that pulls multiple query results. The major issue is that each section, once clicked on has many lines that are not visible unless the scroll bar (which appears...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.