MsgBox

A

an

Hi!

I have a combobox to show us a taken plan number.

To add new procedures to new plan I need to write new plan number in one
textbox.

I would like a MsgBox with alert, if I try write a new number in TextBox to
plan field if it already exist in combo, or in original T_Plans (with plan
number field).

Thanks in advance.
an
 
M

Maurice

An,

Here's some functionality to do some checking -> Place the function in your
code as well.

In your textbox before_update you can place

Private Sub Product_BeforeUpdate(Cancel As Integer)
if CheckExisist(me.textbox) then
msgbox "Number already exists", vbCritical
cancel=true
end if
End Sub


Function CheckExists(iNumber) As Boolean
Dim rst As ADODB.Recordset
Dim intNumber As Integer

Set rst = New ADODB.Recordset
intNumber = "Plannumber ='" & iNumber & "'"

rst.Open "t_Plans", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic, adCmdTable

With rst
.Find intNumber
Do While Not rst.EOF
CheckExists= True
.Find intNumber, 1
Loop
End With

rst.Close
Set rst = Nothing
End Function


One thing though; you have to replace the fieldnames and tablenames with
your field and tablenames (so in the function replace plannumber with your
[plan number] fieldname.

hth
 
A

an

Ok, M.

Work fine after correct CheckExisist and intNumber
Thank you very much for help and explanation.
an

Maurice said:
An,

Here's some functionality to do some checking -> Place the function in your
code as well.

In your textbox before_update you can place

Private Sub Product_BeforeUpdate(Cancel As Integer)
if CheckExisist(me.textbox) then
msgbox "Number already exists", vbCritical
cancel=true
end if
End Sub


Function CheckExists(iNumber) As Boolean
Dim rst As ADODB.Recordset
Dim intNumber As Integer

Set rst = New ADODB.Recordset
intNumber = "Plannumber ='" & iNumber & "'"

rst.Open "t_Plans", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic, adCmdTable

With rst
.Find intNumber
Do While Not rst.EOF
CheckExists= True
.Find intNumber, 1
Loop
End With

rst.Close
Set rst = Nothing
End Function


One thing though; you have to replace the fieldnames and tablenames with
your field and tablenames (so in the function replace plannumber with your
[plan number] fieldname.

hth
--
Maurice Ausum


an said:
Hi!

I have a combobox to show us a taken plan number.

To add new procedures to new plan I need to write new plan number in one
textbox.

I would like a MsgBox with alert, if I try write a new number in TextBox to
plan field if it already exist in combo, or in original T_Plans (with plan
number field).

Thanks in advance.
an
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top