473,411 Members | 1,997 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,411 software developers and data experts.

Need to trap blank new record on form

14
Hi all,

I am having trouble finding out how to stop a new record showing on my form when there are no records showing in my underlying query

Query criteria is populated from a form text box and then I use a cmd button to open the form.

cmd button on click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_SearchJobNoForm"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!F_SearchJobNoForm.RecordSource = "Q_SearchJobRefNo"


I have on Form_load to just maximise the form and that's it.

I can set the form to not allow additions but it just shows a blank form and the user has to shut it down using the x in the top right corner.

Best way to implement this and trap the blank record before the user sees the form?

I'm pants at access but willing to try very hard ;o)

Appreciate any help
Jul 5 '07 #1
4 1892
JKing
1,206 Expert 1GB
Hi by adding a few more lines you can check to see if the supplied criteria will return any results in your query before opening the form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_Click()
  2.  
  3. Dim db As DAO.Database
  4. Dim rs As DAO.Recordset
  5. Dim stLinkCriteria as String
  6. Dim stDoc as String
  7.  
  8. Set db = CurrentDB
  9. Set rs = db.OpenRecordset ("qryYourQuery", dbOpenDynaset)
  10.  
  11. stDoc = "frmYourForm"
  12. stLinkCriteria = "yourCriteria"
  13.  
  14. rs.FindFirst stLinkCriteria
  15.  
  16. If rs.NoMatch Then
  17.     MsgBox "Search criteria returns 0 results.  Please try again.", vbOkOnly + vbInformation, "Sorry!"
  18. Else
  19.     Docmd.OpenForm stDoc,,,stLinkCriteria
  20. End If
  21.  
  22. rs.Close
  23.  
  24. Set db = Nothing
  25. Set rs = Nothing
  26. End Sub
  27.  
rs.NoMatch returns true if there are no records in the query that match your stLinkCriteria.

Be sure to replace "qryYourQuery" with the name of the underlying query of the form you want to open. Sames goes with frmYourForm and yourCriteria be sure to replace them with your own values.
Jul 5 '07 #2
leeg
14
Thank you.

Sorry for being a bit thick but I have tried your code and get an error

"runtime error '3061' Too few parameters. Expected 1."

When I debug it highlights (line 7.)
Set rs = db.OpenRecordset("Q_SearchJobRefNo", dbOpenDynaset)

Here's the code I put in and substituted the names as per your message

I have rem'd line 9 as I'm unsure what this variable is doing. The query field filter is populated using the text box on another form?

1. Private Sub comViewSearch_Click()

2. Dim db As DAO.Database
3. Dim rs As DAO.Recordset
4. Dim stLinkCriteria As String
5. Dim stDoc As String
6. Set db = CurrentDb
7. Set rs = db.OpenRecordset("Q_SearchJobRefNo", dbOpenDynaset)
8. stDoc = "F_SearchJobNoForm"
9. 'stLinkCriteria = "yourCriteria"
10. rs.FindFirst stLinkCriteria
11. If rs.NoMatch Then
12. MsgBox "Search criteria returns 0 results. Please try again.", vbOKOnly + 13. vbInformation, "Sorry!"
14. Else
15. DoCmd.OpenForm stDoc, , , stLinkCriteria
16. End If
17. rs.Close
18. Set db = Nothing
19. Set rs = Nothing
20. End Sub

Any more help would be appreciated

Graeme
Jul 5 '07 #3
JKing
1,206 Expert 1GB
I believe the problem is that your query includes parameters which were allowing you to previously filter the form. What I suggest is removing those parameters from the query.

This is where stLinkCriteria comes in. The purpose of the variable stLinkCriteria is to pass it to the openform command as the where statement for the underlying query of the form. So on your first form with your command button you should include a textbox for the user to type into. Then when they click the command button you build your criteria. For example:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[field] = " & Me.txtSearch
  2.  
[field] would be the field in the query that you want to search on like and ID and Me.txtSearch would be the reference to the textbox on your search form.

Now when we pass this into the FindFirst method of the recordset it will search for the first occurence in the query that matches the user's input for that field. If there's no matches prompt the user and dont open the form. If there is a match open the form with that criteria.

If this seems confusing and you require a little more help with examples more specific to your own database then I'll need you to supply me with a few more things. I'll need to see the sql for the query behind your second form, the name of the field you want to search by and it's data type(i.e. text, number, date) and the name of any controls(i.e. textbox, combobox, listbox) on your search form that you're using to build your criteria.
Jul 5 '07 #4
leeg
14
Thanks very much. I use vb badly and access badly so between the two, confusion arises for me.

That makes sense what you're saying. I have to go now and will have a go at this tomorrow.

Appreciate your help!
Jul 5 '07 #5

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

Similar topics

2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
19
by: Joe Scully | last post by:
Hi all, I am having trouble with access adding a blank record to a subform everytime I finish entering data and closing the form. (The form and subform are based on the one table) When...
2
by: Johm | last post by:
How can i go to the next blank record in the table , such a blank record exists ? In my form Customers, i have a command button with the following command : DoCmd.GoToRecord , "", acNewRec...
1
by: Tim Graichen | last post by:
Hello, I have a main form with one subform. The main form displays a record from TableOne (PCID) This is a corporate software tracking utility that works like this: Main form...Choose PCID...
5
by: ChadDiesel | last post by:
My basic question is why does my print report button on my subform print a blank report when my cursor is on a blank entry line? Here is a more detailed explanation of my problem. I have a...
5
by: bobh | last post by:
Hi All, A clients database (built by another and not very well but, its what I have to work with) has bound forms that display customer information and when printed is three pages long. The...
4
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that...
2
by: ManningFan | last post by:
I've got a continuous form. The query behind it is updateable, but I don't want the continuous form to display a blank record at the bottom. I've set AllowDeletions to false, AllowAdditions to...
2
by: EManning | last post by:
I posted a question on 5/5/08 asking how to trap an error caused by multiple users trying to access the same patient. Here's what I posted: "Using A2003. I've got an FE with a main form with a...
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?
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
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
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...

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.