ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking a text box to make sure a code exists in our SQL Server (https://www.excelbanter.com/excel-programming/362939-checking-text-box-make-sure-code-exists-our-sql-server.html)

Angelique Worrell

Checking a text box to make sure a code exists in our SQL Server
 
Sorry for posting this in two rooms. I couldn't help but notice that no
one's questions were answered on the other post.

I am creating a data entry program that will check a premiumcode from
our prmprdtbl before the operator advances to the next text field. I
currently have it set up that if the operator types "PRM" into the
transactiontype that the application will automatically insert some of
the fields for the operator.

Private Sub cboTransactiontype_LostFocus()
If cboTransactiontype.Text = "NOM" Then
cboPaymentType.Text = "NOM"
txtTransAmount.Text = "0.00"
cmdDESave.SetFocus
ElseIf cboTransactiontype.Text = "PRM" Then
cboPaymentType.Text = "NOM"
txtTransAmount.Text = "0.00"
txtTransPremCode.SetFocus
End If
End Sub

However, when I try validating the premiumcode, It doesn't do what I'd
like for it to do.

Private Sub txtTransPremCode_LostFocus()
If rstPremCode.State = adStateOpen Then rstPremCode.Close
rstPremCode.Open "select * from prmprdtbl where prmcode = '" &
txtTransPremCode.Text & "'", cn
If rstPremCode.EOF = True Then
MsgBox "You must insert a valid premium code here", vbInformation
txtTransPremCode.SetFocus
SendKeys "{Home}+{End}"
Else
txtTransPremCode.Text = UCase(txtTransPremCode.Text)
txtTransQty.SetFocus
End If
End Sub

It shows the messagebox even though I haven't advanced past it - or lost
focus. It also won't highlight the txtTransPremCode field if I type a
code in it that I know doesn't exist in the prmprdtbl. I seriously need
some help. Any suggestions would be greatly appreciated.

Thank you very much,

Angelique


All times are GMT +1. The time now is 07:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com