I have this piece of code that works, but for the life of me I can't figure out what event/module to put it under. In my form, a user generates a number by filling out an unbound form and clicking a command button. The command button then sets the value of InsightId through a calculation. This is not the problem. Then, what I want to happen is, have a disabled textbox (Country) be populated depending on the values. The problem is, I cannot figure out what event/module to put the code under. I tried InsightId_Afterupdate, and the code works if you actually go in and manually change anything, but not if you generate the number with the form (the way 99% of users will be using it). I tried InsightId_Change, and same deal. I tried including it in the code that generates the InsightId in the unbound form, but for some reason that does not work for me--I think because it's both setting the value of InsightId and setting Country by the value of InsightId (I don't know why that would be the case, but it appears to be the case).
I guess worst case scenario I could just tie it to some arbitrary event, like the form having any information be entered, or something like that, but that seems messy/a bad habit to get into.
So, the short of it is, I want to find an event that takes place once InsightId is generated by pressing a command button, and AfterUpdate and Change don't seem to be working. What event can I tie it to?
I don't think any of my code is the issue since it's works perfectly fine when the changes are happening manually, just not when it's generated by VBA.
the associated code is below
Weirdly, if I do in any of those places
it inputs the word "baseball" in just fine, so maybe it is a problem with my code? But again, since it works elsewhere I think it has to do with me just not getting where/when to place it so it works properly
I guess worst case scenario I could just tie it to some arbitrary event, like the form having any information be entered, or something like that, but that seems messy/a bad habit to get into.
So, the short of it is, I want to find an event that takes place once InsightId is generated by pressing a command button, and AfterUpdate and Change don't seem to be working. What event can I tie it to?
I don't think any of my code is the issue since it's works perfectly fine when the changes are happening manually, just not when it's generated by VBA.
the associated code is below
Code:
'generating the Insight Id'
Private Sub Command4_Click()
If IsNull(CommID) Then
Beep
MsgBox "you cannot leave community blank", vbOK
Exit Sub
Else: Forms![test lines]![InsightID] = NewInsightID()
End If
DoCmd.Close acForm, "Generator"
Beep
MsgBox "Please write down the Insight ID and your initials on the paper survey before proceeding"
Forms![test lines]![InsightID].Enabled = True
Forms![test lines]![q1].SetFocus
End Sub
'the part that I thought worked and i just need to stick somewhere'
Forms![test lines]![Country] = Baseball()
Public Function Baseball() As String
Select Case InsightID
Case 1 To 199
Billio = "United States"
Case 200 To 299
Billio = "Spain"
Case 330 To 666
Billio = "Mexico"
End Select
Baseball = Billio
End Function
Weirdly, if I do in any of those places
Code:
Forms![test lines]![Country] = "Baseball"
Last edited: