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

Record Not Saved In Table & Does not show up in the Form

P: 10
I have been working with a database that was already created by somebody else, who now no longer works here, so I cant ask any questions.

None the less, there is a table 'Ascertainment' which prior to my changes new record was saved in the Table, but when you bring up the form it was blank, the input for new record consisted of Text Boxes.

I wanted to validate the data, and changed the text boxes to combo boxes, now new record does not save in the table at all, as well as does not show up in the form. Please Help, here is the Action code to when you click the 'Done' Button.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cmdDone_Click()
  4.  
  5.     Dim response As Integer
  6.     Dim strLinkCriteria As String
  7.     Dim curIDNum As String
  8.     Dim txtRqd As String
  9.     If IsNull(Me![txtIDNUMBER]) Then
  10.         curIDNum = ""
  11.     Else
  12.         curIDNum = Me![txtIDNUMBER]
  13.     End If
  14.  
  15.     strLinkCriteria = "[IDNUMBER] = " & """" & curIDNum & """"
  16.     strFormName = "Main"
  17.  
  18.     If Me.Dirty = True Then
  19.         'user has entered or made changes to data on form
  20.         response = MsgBox("Would you like to save changes?", vbYesNoCancel)
  21.         If response = vbYes Then
  22.             'check for required textboxes (tagged 1 on form) without entries
  23.             txtRqd = checkRqdEntries(Me.Name, 1)
  24.             If Not txtRqd = "" Then
  25.                 MsgBox txtRqd & " requires data before you proceed.", vbCritical
  26.                 Exit Sub
  27.             End If
  28.             DoCmd.Close acForm, Me.Name
  29.             'continue on to main page
  30.             If intaddentry = 1 Then
  31.                 'open main page in entry mode
  32.                 DoCmd.OpenForm "Main", , , , acFormAdd
  33.                 [Forms]("Main")![IDNUMBER] = curIDNum
  34.             'Else
  35.                 'open main page with corresponding record in contacts table
  36.                 'DoCmd.OpenForm "Main", , , strLinkCriteria
  37.             End If
  38.         ElseIf response = vbNo Then
  39.             Me.Undo
  40.             DoCmd.Close acForm, Me.Name
  41.             'if user decides not to save new patient, switchboard will open
  42.             'otherwise:
  43.             'If Not intaddentry = 1 Then
  44.                 'user has chosen not to save changes made to existing patient
  45.             '    DoCmd.OpenForm "Main", , , strLinkCriteria
  46.             'End If
  47.         Else
  48.             'cancel
  49.             strFormName = "Ascertainment"
  50.             Exit Sub
  51.         End If
  52.     Else
  53.         'no changes have been made to the data on the form
  54.         DoCmd.Close acForm, Me.Name
  55.         'if user decides not to save new patient, switchboard will open
  56.         'otherwise:
  57.         'If Not intaddentry = 1 Then
  58.         '    DoCmd.OpenForm "Main", , , strLinkCriteria
  59.         'End If
  60.     End If
  61. End Sub
Mar 17 '08 #1
Share this Question
Share on Google+
11 Replies


P: 10
Also I wanted to add that in the "Main" Form I have a button that leads to the "Ascertainment" form and here is the code to that button, just in case this helps with understanding why there is a problem.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAscertainment_Click()
  2.     Dim curID As String
  3.     Dim recordExists As Boolean
  4.     curID = Me![IDNUMBER]
  5.  
  6.     run = MainNavigate()
  7.     If boolCancel = True Then
  8.         Exit Sub
  9.     Else
  10.         If run = False Then
  11.             DoCmd.Close acForm, Me.Name
  12.             Exit Sub
  13.         Else
  14.             recordExists = FindRecord("Ascertainment", "IDNUMBER", curID)
  15.             If recordExists Then
  16.                 DoCmd.OpenForm "Ascertainment", , , "[IDNUMBER] = """ & curID & """"
  17.             Else
  18.                 DoCmd.OpenForm "Ascertainment", , , , acFormAdd
  19.                 [Forms]("Ascertainment")![txtIDNUMBER] = curID
  20.             End If
  21.         End If
  22.     End If
  23. End Sub
Mar 17 '08 #2

Scott Price
Expert 100+
P: 1,384
Hello AndrewDB,

When including code in your thread, and especially when including such a long portion of code, please use the [code] tags provided, as indicated in the Reply Guidelines to the right of the Reply/Message window. They are simple to use: select your code text, then click on the # icon on menu bar of the Message window.

MODERATOR
Mar 17 '08 #3

P: 10
Anyone?
Please?
Maybe?
Mar 18 '08 #4

Scott Price
Expert 100+
P: 1,384
The code you have posted doesn't have any references in it to the text boxes converted to combo boxes that you mentioned having changed. Also, there is a reference in Line 23 of your first post to a user defined function named: chkRqdEntries...

Please indicate what code you changed, and post the relevant code changes. Please also post the code for the chkRqdEntries function.

Regards,
Scott
Mar 18 '08 #5

P: 10
Thats the thing, the only thing I have changed was not the actual code, but from the Form 'Ascertainment' where there were fields, I took them out and replaced them with combo boxes. Thats all, fortunately I have fixed the problem of new records not being recorded. Thats half the battle. But I still can not understand why entered records do not show up when I click on the 'Ascertainment' button from the 'Main' menu? Its just a blank form, even though the record exists in the Table.

Please Help.

Here is the code for the function you have asked:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Function checkRqdEntries(frmName As String, tagNo As Integer) As String
  4.     Dim contrl As Control
  5.     checkRqdEntries = ""
  6.     For Each contrl In [Forms](frmName).Controls
  7.         If TypeName(contrl) = "TextBox" And contrl.Tag = tagNo Then
  8.             If IsNull(contrl) Then
  9.                 checkRqdEntries = contrl.Name
  10.                 Exit Function
  11.             End If
  12.         End If
  13.     Next contrl
  14. End Function
  15.  
Thank You for your Time
Mar 18 '08 #6

Scott Price
Expert 100+
P: 1,384
What's the control source of your combo boxes? Combo boxes have both a control source and a row source.

I'm assuming you have set the row source correctly, but nothing will initially show in the combo box if you do not set the control source.

Regards,
Scott
Mar 18 '08 #7

P: 10
Row Source contains the two columns that are my 'Choices' with description that I want to display, and the corresponding code number that I want to store in the table.

Control Source is the reference to the variable/column where the information is being stored in the table. In one of the cases for example I have a combo box for 'Referred by' which is stored in my 'Ascertainment' table under variable REFDBY, which is the control source for that combo box.

So it does seem like there is reference to it, I just don't understand why it wont display, very strange.

Andrew
Mar 19 '08 #8

missinglinq
Expert 2.5K+
P: 3,532
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Function checkRqdEntries(frmName As String, tagNo As Integer) As String
  4.     Dim contrl As Control
  5.     checkRqdEntries = ""
  6.     For Each contrl In [Forms](frmName).Controls
  7.         If TypeName(contrl) = "TextBox" And contrl.Tag = tagNo Then
  8.             If IsNull(contrl) Then
  9.                 checkRqdEntries = contrl.Name
  10.                 Exit Function
  11.             End If
  12.         End If
  13.     Next contrl
  14. End Function
  15.  
I'm not still clear on exactly what you're doing here, but in Line # 7 of the above code you have a line

If TypeName(contrl) = "TextBox" And contrl.Tag = tagNo Then


Since you've converted some textboxes to comboboxes you may need to modify this code to to include comboboxes.

Linq ;0)>
Mar 19 '08 #9

P: 10
How would I do that?

Would it be like this?

If (TypeName(contrl) = "TextBox" OR "ComboBox") And contrl.Tag = tagNo Then

?
Mar 19 '08 #10

missinglinq
Expert 2.5K+
P: 3,532
No, when using And/Or you have to include the complete evaluation expression

Expand|Select|Wrap|Line Numbers
  1.  If (TypeName(contrl) = "TextBox" OR TypeName(contrl) = "ComboBox") And contrl.Tag = tagNo Then
Linq ;0)>
Mar 19 '08 #11

P: 10
I have tried that as well, nothing changes. Still the when I click on the button the Form comes up with empty cells/combo boxes. How strange! WHY? Anybody?
Mar 25 '08 #12

Post your reply

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