By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,671 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,671 IT Pros & Developers. It's quick & easy.

Command Button Trouble

P: 44
How can I get a command button to open up a pop up form with information related to the main form? I have an "Employees" form with a cmdbutton to open "SpsInfo" form. When the cmd button is clicked i am able to enter the information on the spouse, but if i go back to the main form and click on the cmd button the information is gone on the form. I need the cmd button to pop open the "SpsInfo" form with the related spouse on the main form. How can i keep the information from disappearing?
May 14 '08 #1
Share this Question
Share on Google+
5 Replies


100+
P: 222
How can I get a command button to open up a pop up form with information related to the main form? I have an "Employees" form with a cmdbutton to open "SpsInfo" form. When the cmd button is clicked i am able to enter the information on the spouse, but if i go back to the main form and click on the cmd button the information is gone on the form. I need the cmd button to pop open the "SpsInfo" form with the related spouse on the main form. How can i ke ep the information from disappearing?
I think the better way now is to use the wizard of MS access. assign a button and then choose open form here you can chose the criteria you want (usually primary key = to the other primary key)

try it it might be the answer of your post.


Have nice day


WASSIM S DACCACHE
May 14 '08 #2

Expert Mod 2.5K+
P: 2,545
Hi Zulema. You have not provided full enough details of where exactly the spouse information is stored, and what the recordsource is for your pop-up form. I assume that the spouse field or fields in the separate form are also part of the same employee table and not a separate table. Normally, the relationship of spouse to employee is 1-1 so a separate table is not used to store such data. Please advise if this is not the case here.

It would appear that either (a) your pop-up form is not bound to the spouse details field in the underlying query or table, or (b) you are not filtering the employee ID correctly when you open the spouse form. In case (a) if you enter data into an unbound text box the data is lost when the form is closed. In case (b) the data is still available for some record that you have overwritten, just not the one you think it should be.

I suspect that case (a) is more likely.

We need to know the recordsource of your pop-up form, and how you are opening it (ie what filter is being applied to make sure it is the correct employee's record that is opened).

-Stewart
May 14 '08 #3

P: 44
Thanks for responding Stewart. The spouse fields are are part of a separate table "SPS INFOtbl". This is the code on the command button to open the pop up form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command444_Click()
  2. On Error GoTo Err_Command444_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frmSPS INFOtbl"
  8.  
  9.     stLinkCriteria = "[SS#]=" & "'" & Me![SS#] & "'"
  10.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  11.  
  12. Exit_Command444_Click:
  13.     Exit Sub
  14.  
  15. Err_Command444_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Command444_Click
  18.  
  19. End Sub
May 14 '08 #4

Expert Mod 2.5K+
P: 2,545
Hi Zulema. Code opening the form seems OK - assuming that your ID field SS# is indeed a string (going by the single quotes before and after the reference to the field in the Docmd.Openform line).

One other possible cause of this apparent 'loss' of data is if the form frmSPS INFOtbl is opened in Add mode instead of Edit. Open the form in design mode and check its Allow Edits property, which should be set to Yes. If it is set to No and Allow Additions set to Yes you will be able to add new records, but not see or edit any existing data.

If the properties are OK then check directly at table level whether or not data is being stored in your spouse info table. If it isn't, either form frmSPS INFOtbl is bound to a non-updatable source, or the control you are updating is not bound to an underlying field, or the record filtering on the SS# field is not matching any existing records.

One other thing: as you are using a separate table for spouse information, if you are adding new staff records and then adding spouse data from within that entry on your staff form you must save the staff record before opening the spouse form. Otherwise, there is not yet an employee reference to match.

The record save can be achieved by adding
Expand|Select|Wrap|Line Numbers
  1. if me.dirty then me.dirty=false
before the Docmd.openform statement.

-Stewart
May 15 '08 #5

NeoPa
Expert Mod 15k+
P: 31,276
Zulema,

As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

ADMIN.
May 16 '08 #6

Post your reply

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