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

Error with command button which opens form to specific record

4
I have 2 forms, "Staff" and "Security" (without the ""'s). The Staff form has the following fields:
staff_ID
staff_name
staff_number
staff_DOB
priority

The Security form contains the following fields:
staff_ID
staff_pass
priority

The staff_ID fields in both forms are linked by a one-to-one relationship.
I have a command button (Command22) in the Staff form which, when pressed, opens the security form to the corresponding staff_ID value (for example, if I navigate to the record in the Staff form where staff_ID = 6 and press the Command22 button, the Security form is opened and the record in the Security form where staff_ID = 6 is displayed). Below is the code for the On Click event of the Command22 button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command22_Click()
  2. On Error GoTo Command22_Click_Err
  3.  
  4.     DoCmd.OpenForm "Security", acNormal, "", "[staff_ID]=" & staff_ID, , acNormal
  5.  
  6.  
  7. Command22_Click_Exit:
  8.     Exit Sub
  9.  
  10. Command22_Click_Err:
  11.     MsgBox Error$
  12.     Resume Command22_Click_Exit
  13.  
  14. End Sub
However, when I create a new record in the Staff form and press Command22, a "Syntax error (missing operation) in query expression '[staff_ID]='" error comes up. I think this is because the database cannot find a corresponding staff_ID value in the Security form. What needs to be done so that, when a new record is created in the Staff form and the Command22 button is pressed, the Security form is opened to a new record?

Thanks in advance,
extrym
Jun 12 '10 #1
3 8868
gnawoncents
214 100+
Hello, extrym.

This should be a fairly easy problem to resolve, but we need a little extra data. When you say,
The staff_ID fields in both forms are linked by a one-to-one relationship.
do you mean that you have two distinct tables linked in a query by a one-to-one relationship? If so, are the forms using that query as their Record Source or the tables directly?

If they are separate tables, how does the staff_ID get into each of the tables initially?

Please explain a bit more and we'll be glad to help.
Jun 12 '10 #2
ADezii
8,834 Expert 8TB
@extrym
Expand|Select|Wrap|Line Numbers
  1. 'Force a Record Save
  2. If Me.Dirty = True Then Me.Dirty = False
  3.  
  4. 'No Security Record for Staff ID
  5. If DCount("*", "tblSecurity", "[staff_ID]=" & Me![staff_ID]) = 0 Then
  6.   DoCmd.OpenForm "Security", acNormal, , , acFormAdd
  7. Else
  8.   DoCmd.OpenForm "Security", acNormal, "", "[staff_ID]=" & staff_ID, , acNormal
  9. End If
Jun 12 '10 #3
extrym
4
@ADezii
the same error appears again...

@gnawoncents
yes, they're two seperate tables. The staff_ID is actually a field in the Staff table. The staff_ID field in the Security table is just a lookup of the original staff_ID.

* edit *

Okay, I've solved it! I used a few macros to get the job done:
Macro name
Macro6
  • OnError
    • Macro Name. Macro8
  • RunCommand
    • SaveRecord
  • OpenForm
    • Security، Form، ، ="[staff_ID]=" & [staff_ID]، ، Normal
Macro8
  • RunCommand
    • SaveRecord
  • OpenForm
    • Security. Form . . . Normal
  • GoToRecord
    • Form. Security. New

When I converted it to VB code it didn't work...so I stuck to macros. If this method is wrong, please post.
Jun 14 '10 #4

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

Similar topics

3
by: Simone | last post by:
Hello!!! Here is the thing. I have had this problem and I want to address it now where in the next and previous button DoCmd.GoToRecord , , acNext - DoCmd.GoToRecord , , acPrevious I wish the...
4
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants...
3
by: cmp80 | last post by:
I have a database that I am using to store student data. There are two tables and two forms to display the data: Tables tbStudent tbRE Forms fmStudent fmRE
3
emandel
by: emandel | last post by:
I am an armature access programmer trying my best to design my own database so your patience and detailed instructions is much appreciated. Here is my question: How do I get a command button (on...
1
by: Jimmy | last post by:
There is a command button on the form I'm working on. The form displays one record. The command button creates a new record by copying selected data from the current record: Dim dbs As Database...
2
by: buddyr | last post by:
Hello, I have a cmd button on form to search for serial number. I notice when I search for record-that if I don't start at the beginning of records I might not find the record. example: if I am...
10
by: orajat | last post by:
hi, how do i setup a command button on a page form that when clicked, saves system time in a particular field of a table ?
1
by: cvillav | last post by:
Hello, I am new to Access and this forums, I have two tables and two forms to display the data. Tables Tbuilding Tcriteria Forms fmbuilding
16
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The...
7
by: Bre035 | last post by:
Created a database that I want to be maintained and updated by the Department designated Admins. I have an user table that set specific individuals access to Admin and created admin form and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.