467,122 Members | 1,257 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,122 developers. It's quick & easy.

VB Close command creating roecords

I have a form and it is to creat a 'link' between a project and a company. Creating a record form this table will simply create a record in a databse with the company ID and project ID. Project ID is selected form a drop down bax and Company ID is selected from a combo box. I am trying to create a script that if you click exit form, and one or the other, or both of the fields have a selection it will bring up message box and inform the user of the situation, and what will happen. That i am not having trouble with. I am having trouble with the Docmd.close! it seems that this command creates a new record, even when the
DoCmd.GoToRecord , , acNewRec command is not there. The form is set as a data entry form. I have included my if statements but i dont think the problem is there. I have taken out the close commands and records are not created, i put them back in and the form closes and creates the record. How do i close the form without it creating the record.

P.S. i have also tried doCmd.close as upposed to coCmd.close acForm, "form_Company-Project" with the same record creating result.

Any help would be greatly appreciated

Cheers,

Oxford Consult

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command22_Click()
  2.  
  3. If Me.Combo25.Value = 0 Then
  4.     If Me.Combo8.Value = 0 Then
  5.         DoCmd.Close acForm, "Form_Company-Project"
  6.         DoCmd.OpenForm "Form_Mainpage"
  7.     Else
  8.         MsgBox "You have only selected a company and no link will be created", vbCritical, "Note"
  9.         DoCmd.Close
  10.         DoCmd.OpenForm "Form_Mainpage"
  11.     End If
  12. Else
  13.     If Me.Combo8.Value = 0 Then
  14.         MsgBox "You have only selected a project and no link will be created", vbCritical, "Note"
  15.         DoCmd.Close acForm, "Form_Company-Project"
  16.         DoCmd.OpenForm "Form_Mainpage"
  17.     Else
  18.         zmessage = MsgBox("You have slected a company and project to create a link but have not created a link." & vbCrLf _
  19.         & "Do you wish to do so now?", vbYesNo + vbQuestion, "Link selected but not created")
  20.         If zmessage = 6 Then
  21.             MsgBox ""
  22.             MsgBox "A link has been created", vbInformation, "Note"
  23.             DoCmd.Close acForm, "Form_Company-Project"
  24.             DoCmd.OpenForm "Form_Mainpage"
  25.         Else
  26.             DoCmd.Close acForm, "Form_Company-Project"
  27.             DoCmd.OpenForm "Form_Mainpage"
  28.         End If
  29.     End If
  30. End If
  31.  
  32. End Sub
  33.  
Jun 21 '07 #1
  • viewed: 1719
Share:
1 Reply
I have figured it out. I found another forum with this same problem and tried some of thier remedys. There final solution was to use :

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdExit_Click()
  2.     Call DoCmd.Close(ObjectType:=acForm, ObjectName:=Me.Name)
  3. End Sub
  4.  
however this did not work for me, and I kept getting the same error. In the end i tried the undo function that didnt work for them but did for me. Might have somehitng to do with the messageboxes and keeping them on focus.

Expand|Select|Wrap|Line Numbers
  1. Call Me.Undo
  2. DoCmd.Close
  3.  
Hope this helps anyone else with a simlar probelm.

Cheers,

Oxford
Jun 21 '07 #2

Post your reply

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

Similar topics

2 posts views Thread by Guy Babbitt | last post: by
35 posts views Thread by Eric Sabine | last post: by
reply views Thread by bonita | last post: by
4 posts views Thread by RICHARD BROMBERG | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.