473,799 Members | 3,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open form on specific record via a string based field

137 New Member
I've got a form that allows users to "save the current record to drafts" if they haven't finished writing all the data for that record. This saves it in it's current state, which puts it in a temporary table. The record is also tagged with the name of the user who created it.

What I'm trying to do is to force the form to open up and load this record when the form is loaded/opened. The structure of the database only allows users to have one draft at once, as it should be dealt with next time the form is opened, so there should only be 1 record in this temporary table that is specific to that user.

I've tried doing:

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim strCriteria As String
  3.  
  4. Set rst = Me.RecordsetClone
  5. strCriteria = ("[LastEditedBy]='" & GUsername & "'")
  6.  
  7. rst.FindFirst (strCriteria)
  8. If rst.NoMatch Then
  9.     MsgBox "No entry found."
  10. Else
  11.    Me.Form.Bookmark = Me.RecordsetClone.Bookmark
  12. End If
but this just always returns the "no entry found" message, and then goes to a new record.

I've also tried sticking the criteria into the code for opening the form from the main menu, but again that just opens it to a new record.

I have disabled any old code on the On_Load event that used to tell the form to go to a new record.

Can anyone see something wrong with the code I've used?
Can FindFirst only be used for numerical values? If so, is there an alternative for string based fields?


This seems like such a stupidly simple thing to be stuck on, and yet I can't figure it out!

Thanks.

Adam.
Mar 9 '11 #1
6 3070
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Question, You say it always goes to a new record, but do you always get the msgbox of No Entry Found?

If this is called locally from your form, you could use:
Me.RecordSet.Fi ndFirst strCriteria
instead of going through the recordsetclone (unless you have some reason not shown here)
Mar 9 '11 #2
Lysander
344 Recognized Expert Contributor
Where is GUsername coming from?

Have you tried single stepping through the code and checking that strCriteria holds the correct value?
Mar 9 '11 #3
Adam Tippelt
137 New Member
Yes it always gives the No Entry Found msgbox.

Me.RecordSet.Fi ndFirst strCriteria just took me to a new record.

GUsername is a global variable that captures the name of the user when they log in.

Trying to step through code doesn't appear to do anything - I've not really done much debugging with code stepping, so not sure what I should expect to see/do when I click Step Into, or whether I need to 'prep' the code for debugging, so to speak (add breaks etc.).
Mar 9 '11 #4
Adam Tippelt
137 New Member
*sigh* Just found a solution and it was as stupidly obvious as I thought it would be.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Me.Filter = "[LastEditedBy]='" & GUsername & "'"
  3. Me.FilterOn = True
Mar 9 '11 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
As far as I can tell your first code should work.

Remember however that when your using a variable such a GUserName that if you meet an unhandled error, the GUserName will loose its value.

Therefore to check that it has a value (When debugging), add on the line before either:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "GUserName:" & GUSerName
Or
Expand|Select|Wrap|Line Numbers
  1. Msgbox "GUserName:" & GUSerName
I have a way to solve the problem of the variable loosing its value, if you want it.
Mar 9 '11 #6
Adam Tippelt
137 New Member
The main menu for my database has a field that holds the name of the current user, AKA GUsername. I've been using that as an indication of whether the global variables have lost their values as the Current User field goes blank.
I always go back to the main menu when testing new functionality, firstly to check that the global variables are still holding their values, and secondly to make sure that the form operates correctly, and I don't encounter any unusual behaviour by going straight from Design View to Form View.

I don't know why the first code didn't work, as to me it made logical sense, and I've used similar code on a different form which didn't have any problems. Weird :S
Mar 9 '11 #7

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

Similar topics

2
7141
by: RC | last post by:
I would like to go to a specific record based on what the user types in a text box on a form. I have a table named: Boxes in the table there is a field named: BoxNumber a form named: BxForm and a text box on the form named: GetNumBox I want to type a number in the text box and then press the enter key on the keyboard and go to the corresponding record.
2
11287
by: nkoske | last post by:
I have a form with a subform in datasheet view and I have a event on one of the fields in the subform, so that the user can double click it and go to expanded information based on that field. I'm using this code: Private Sub SpecimenNum_DblClick(Cancel As Integer) DoCmd.OpenForm "RDDevice", , , " = '" & Me! & "'" End Sub
3
10579
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The other one is Next button which i created to open another form "frmSummary" which displays back the records submitted. (i used the wizard to open form and find specific records to display. All these works superb until a review by users where they...
14
25069
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a record on a continuous form and click and edit button. The button runs the open form code. I want the APPID of the current record on the continous form to match the APPID of the record viewed
8
1956
by: narpet | last post by:
Hello all... I'm having a problem getting a query to work. As a matter of fact I can't even seem to get a good start. I have a table with the following example data ID# PRE_ID# POST_ID# DATE 1 1 2 1/1/2001 1 1 2 1/1/2004 1 1 2 1/1/2006 *
10
15335
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some circumstances, this or another user must create an invoice to go with the PO (I know - that makes no sense, but this is the business case). I have the user go to a form to create the invoice:
3
10678
by: DavidB | last post by:
I want to be able to go to a specific record on my form when I open it. The record I want to go to will be dynamic based on the value currently stored in a global variable. The global contains the primary key (long int - BlahBlahID) and there is a field on the form (tbBlahBlahID) that contains the value for this field. I am having a major case of DFUism here because this looks to be a simple request, but my aged brain is stumbling on...
4
2267
by: Martin Bentler | last post by:
I have a form that is locked for editing, adding or deleting. Through the use of a command button I open another form, that allows editing, plus allows the user to other areas of the database, through command buttons. When I click the command button I want to open the second form displaying the CompanyName and information from the first form (the record I had displayed on first form, but open for editing. On the second form I have a command...
1
3248
by: Martin Bentler | last post by:
Right now, I have a form, locked records, on which I have a CommandButton that opens a second form (much like the first) but open for editing, plus allowing the user to manipulate other areas of the data base. I want to have the second form open at the specific record I was working with on the first form. Basically what I am doing is running a find to locate the record after the second form opens, as all I have is DoCmd code to open and close...
5
6551
by: jgarcia187 | last post by:
I have a report that runs based on parameters set in the underlying query. For example, in the "account number" field in the query I've entered in the criteria area. This allows the user to select a certain record. The record opens with all relevant data on a form. From the form, the user can then run specific reports about that record that also use the same criteria. I know there is a way to have access copy the account number from the...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.