Morning!
I'm having a weird problem in VBA on a button click. For no apparent reason the database closes itself. No error, no crash - it just closes. I've compacted and repaired it, recompiled it, but still exactly the same. The strange thing is, if I insert a blank message box at the point in the code where it quits, everything then works perfectly! Also, if you leave Text4 empty so that it displays the message box telling you to enter a code to start, when you then enter something the next time it also works perfectly. Somehow the process of displaying the message box seems to fix whatever the problem is.
Can anyone suggest what might be happening? I've tried pausing the code at that point, I've tried changing the focus to a different control or another form. I've run out of ideas!
Here's the code:
If anyone could make any suggestions I'd be really grateful.
Thanks,
Cavman
I'm having a weird problem in VBA on a button click. For no apparent reason the database closes itself. No error, no crash - it just closes. I've compacted and repaired it, recompiled it, but still exactly the same. The strange thing is, if I insert a blank message box at the point in the code where it quits, everything then works perfectly! Also, if you leave Text4 empty so that it displays the message box telling you to enter a code to start, when you then enter something the next time it also works perfectly. Somehow the process of displaying the message box seems to fix whatever the problem is.
Can anyone suggest what might be happening? I've tried pausing the code at that point, I've tried changing the focus to a different control or another form. I've run out of ideas!
Here's the code:
Code:
Private Sub cmdReqLookup_Click()
Dim strTaleoReq As String
Dim strTaleoID As String
Dim intIDMatches As Integer
Dim strContractID As String
Dim strEmployeeName As String
Dim vbRed As Double
Dim vbBlack As Double
vbRed = RGB(255, 0, 0)
vbBlack = RGB(0, 0, 0)
strTaleoReq = Nz(Me.Text4, "")
If strTaleoReq = "" Then
MsgBox "Please Enter a Taleo Req to start!", vbCritical, "No ID"
Exit Sub
End If
'This is where the database quits. If I add a message box here, it then runs perfectly!
'Disable button
Me.cmdReqLookup.Caption = "Please wait..."
Me.cmdReqLookup.ForeColor = vbRed
Me.cmdReqLookup.Enabled = False
Me.Refresh
ScriptHold (1)
' Count how many ID's there are match the Req entered
intIDMatches = DCount("[ContractID]", "QuerySECIDa")
If intIDMatches < 1 Then
MsgBox "There are currently no matches for this Req in the database. Please check it carefully and ensure there are no extra spaces. If it still isn't recognised, please check the request has been processed correctly."
Me.cmdReqLookup.Caption = "Lookup"
Me.cmdReqLookup.ForeColor = vbBlack
Me.cmdReqLookup.Enabled = True
Exit Sub
End If
If intIDMatches > 1 Then
' Get from ID selector
strTaleoID = IDSelector
Else
' Lookup Taleo ID and display
strTaleoID = DLookup("[TaleoID]", "QuerySECIDa")
End If
Me.Text6 = strTaleoID
' Lookup Contract ID and display
strContractID = DLookup("ContractID", "QuerySECID")
Me.Text9 = strContractID
' Lookup Employee Name and display
strEmployeeName = DLookup("Fullname", "QuerySECID")
Me.Text11 = strEmployeeName
Me.cmdReqLookup.Caption = "Lookup"
Me.cmdReqLookup.ForeColor = vbBlack
Me.cmdReqLookup.Enabled = True
End Sub
If anyone could make any suggestions I'd be really grateful.
Thanks,
Cavman