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

Issue with Duplicate items on DoCmd.Close acForm command

P: 23
My current code (which handles multiple string input's and creates individual fields based on the delimiter through the split() function is:
**Currently the DoCmd.Close is commented out.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveInput_Click()
  3. Dim InputString() As String
  4. Dim i As Integer
  6. InputString = Split(InputName, " ")
  7. For i = 0 To UBound(InputString)
  8.     CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
  9. Next i
  12. 'DoCmd.Close acForm, "InventoryInputF"'
  14. End Sub
Therefore, if I enter 'data1 data2 data3' in the assigned textbox the result in my table is as expected:
field1 data1
field2 data2
field3 data3

My perplexing issue is, if I uncomment the DoCmd.Close acForm."InventoryInputF" which I wrote purely to close the form after saving.... it table now displays the results

field1 data1 data2 data3
field2 data1
field3 data2
field4 data3

You can see that for some reason when I implement the docmd.close code, the data is saved both as its 'lump sum' of all the values IN ADDITION to its proper function of using the split() function.

Anybody have any ideas why? Or maybe another way to close my form with code so I can avoid the DoCmd.Close code??
Apr 25 '17 #1

✓ answered by NeoPa

That smells very heavily of a bound form to me. With something like this you don't want a bound form.

Share this Question
Share on Google+
4 Replies

P: 23

I had an 'undue button' that ran a macro to navigate to a 'new record' when clicked. I didn't realize this worked to 'save what was in the textbox' before moving to a new record.

I switched the macro for
textboxname.value = null and it seems to have solved the issue...

However I'm not sure why that macro for a 'undo' button would affect the code for my 'save input' button and why the 'docmd.close acform' was affected...

The only reasoning to me is that when the 'docmd.close acform' ran, the macro regarded that as altering the information thus saved the total textbox information... effectively saving the split() information from my save button and the lump sum informaiton from my undue button
Apr 25 '17 #2

P: 23
Disregard the Disregard,

the code above hasn't been changed. The macro mentioned in the disregard is still there.

The issue appears whenever I close the form. For example, I enter "data1 data2 data3" and press save, the data saves as 3 individual fields as I want, with "data1 data2 data3" still appearing in the textbox. There is no issue here.

Once I close the form, if the "data1 data2 data3" is still in the textbox, then that information is saved to the table in one field displaying data1 data2 data3.

I have implemented textboxname.value=null after my split() function so that there is never information remaining in the box... but then when I close the form a record with zero input is saved to my table!

In Summary, whenever I close the form, whatever is in the textbox is saved to the table, even if there is nothing there... how can I solve this?
Apr 25 '17 #3

Expert Mod 15k+
P: 31,398
That smells very heavily of a bound form to me. With something like this you don't want a bound form.
Apr 25 '17 #4

Expert 100+
P: 1,107
I would agree with Neopa that you really don't need a bound Form. Especially if you look at the code, no controls are ever referenced. Your blank record and possible missing record in code are unrelated problems.
Apr 28 '17 #5

Post your reply

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