473,473 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Create 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 3040
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.FindFirst 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.FindFirst 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
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 ...
2
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. ...
3
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...
14
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...
8
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# ...
10
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...
3
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...
4
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,...
1
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...
5
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...
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
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
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...
1
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...
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.