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

Swapping lines of code changes results and error.

P: 15
I have a form called Main, and a second form called Create.... I open the Create form from a combobox. Then, just click SAVE, which creates a record, and tries to set a text box to the ID for the new record and set the name of the entity of that new record to another text box.

I have many of these. They all work, except one. It is slightly different from the rest. Those two lines of assignments have worked while I was debugging. The first one encountered works. The second one does not work. So at times one of the text boxes has a value and the other is NULL. Both are supposed to have values.

Here is the sub

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbSaveClose_Click()
  2. Dim x As Integer
  3.  
  4. x = MsgBox("Are you sure you want to save changes?", 4, "Exit?")
  5.  
  6. 'VbNo constant throws back #7
  7. 'VbYes constant throws back #6
  8.  
  9. Me.Txt32 = DLookup("InsuranceCarrierContractID", "ICCDupRecordCheckQ")
  10.  
  11. If x = 7 Then
  12.     Exit Sub
  13.     End If
  14.  
  15. If IsNull(Me.Txt32) Then
  16.     Me.Txt31 = Form_frmMain.Txt65
  17.     DoCmd.RunCommand acCmdSaveRecord
  18.  
  19. ' The preceding code works fine. 
  20. ' Each of the following lines work individually, but only the one executed first works. The other does not appear to execute. I end up with a null in the text box.
  21.  
  22.  
  23.     Forms!frmMain.cboInsuranceCarrierContract = Me.InsuranceCarrierContractID
  24.  
  25.     Forms!frmMain.Txt66 = Me.InsuranceCarrierContractID
  26.  
  27. 'The following code works fine. 
  28.  
  29.     DoCmd.Close
  30.  
  31.     Forms!frmMain!cboInsuranceCarrierContract.RowSource = " SELECT InsuranceCarrierContract.ContractNumber " & _
  32.                                                  " FROM InsuranceCarrierContract " & _
  33.                                                  " ORDER BY InsuranceCarrierContract.ContractNumber;"
  34.  
  35.  
  36.  
  37.     Form_frmMain.cboInsuranceCarrierContract.Locked = False
  38.     Form_frmMain.cboInsuranceCarrierContract.BackColor = Form_frmMain.cboInsuranceCarrier.BackColor
  39.  
  40. Else
  41.     Me.Undo
  42.     DoCmd.Close
  43.  
  44.  
  45. End If
  46. End Sub
Oct 24 '13 #1

✓ answered by topher23

Without a LOT more context, I can't make a specific suggestion, but I will make some general observations.

First, ensure that neither Forms!frmMain.cboInsuranceCarrierContract or Forms!frmMain.Txt66 are doing anything that could cause a change to Me.InsuranceCarrierContractID or each other. If everything looks okay there, try changing the periods in the reference to exclamation points. Although Access allows it (and IntelliSense makes it easy to do it), using the period can cause confusions with properties, whereas using an exclamation point (!) tells Access that you're referencing the default collection and not a property.

Share this Question
Share on Google+
1 Reply


topher23
Expert 100+
P: 234
Without a LOT more context, I can't make a specific suggestion, but I will make some general observations.

First, ensure that neither Forms!frmMain.cboInsuranceCarrierContract or Forms!frmMain.Txt66 are doing anything that could cause a change to Me.InsuranceCarrierContractID or each other. If everything looks okay there, try changing the periods in the reference to exclamation points. Although Access allows it (and IntelliSense makes it easy to do it), using the period can cause confusions with properties, whereas using an exclamation point (!) tells Access that you're referencing the default collection and not a property.
Oct 28 '13 #2

Post your reply

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