Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcinga user to use certain controls up on opening a Form

Status
Not open for further replies.

sanan

Technical User
Apr 15, 2004
139
IR
Hi Every Body

Upon opening a certain Form, What is the best way to force a user to use a certain CommboBox or CheckBox before they can use any other controls on that Particular form?

Another related problem, Using VB codes, how can I choose or set a value of my CommboBox? For example I would like to select the Third value of my Cmmbobox Drop down list,
What is wrong for the following code:

Private Sub Command161_Click()
Me.Combo144.SetFocus
Me![Combo144].Column(1).Row (3)
End Sub

Best Regards
Sanan
 
on open set the focus to the control you require, if they leave the control without filling it create a message box to inform them and set the focus back to that control in the after update event set the focus to the control you require them to go to next.
I have never tried to set a cbo to a certain row I don't if you can without playing around.

Hope this helps
Hymn
 
In the Access help
Specify which row is the default value in a list box or combo box
In a form, you can specify which row is automatically selected in a list box or combo box. This procedure does not apply to data access pages.

Open a form in Design view.
Make sure that the combo box is selected and then click Properties on the Form Design toolbar.
In the DefaultValue property box, type [comboboxname].ItemData(n) where n is the row that you want to use as the default. The ItemData property is zero-based, so type ItemData(0) if you want to make the first row in the list the default. For example, to specify the first row of the SupplierCombo combo box as the default for the combo box, type [SupplierCombo].ItemData(0) in the DefaultValue property box.

Hope this helps
Hymn
 
Hi hymn
I have this code, And They supposed to set or select an Option of my ComboBox,
But They do not work.

Private Sub CheckBox1_Click()
If Me.CheckBox1 = True Then
Me.Combo144.DefaultValue Or
Me.Combo144.ItemData (3)
End If
End Sub

Could you tell me what is wrong for it?

Also I have the following codes:
Private Sub Form_Open(Cancel As Integer) (On open Event of my main form)
DoCmd.GoToRecord , , acNewRec
Me.Combo144.SetFocus
End Sub

And

Private Sub Combo144_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me!Combo144) Or Me!Combo144 = "" Then
strMsg = "You must pick a value"
strTitle = "Bill To Customer Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.Combo144.SetFocus Or cancel = True Or Docmd.cancelEvent
End If
End Sub

As you can see I am trying to accomplish the following:
Upon opening a form first of all start with a New Record, Then setting Focus on a CombBox Then on Moving away from the comboBox If noting is selected, The user first gets a MsgBox, and Then They are not supposed to be able to go to next control, But it does not work.
I do get the MsgBox, but my user can go on to the next control, what is it that I am doing wrong? How can I stop then from moving away from the control?

Best Regards
Sanan

 
First

the simplest way of setting the order in which the focus goes to each control is by using the Tab Stop and Tab Index or Tab Order
tab stop and tab index requires you to go into design view and go into each control ant set them remember they start at zero
tab order go into design view right click and go to tab order and set it on that

Second

What is your first control?

If it is the combo144 then in your code for lost focus
Private Sub Combo144_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me!Combo144) Or Me!Combo144 = "" Then
strMsg = "You must pick a value"
strTitle = "Bill To Customer Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
me.anothercontrol.setfocus
Me.Combo144.SetFocus

End If
End Sub

Note the addition! you cannot set the focus stright back on the control you must send it to another control and then back to your control
try these and see if you get what you require/want

Hope this helps
Hymn
 
Hihymn
Thanks so much, It finally worked,
But I am trying to do the Exact procedure in another control on the same form and it does not work,
From my Combo144 in its Lostfocus and also in AfterUodate event I set the focus on my InvoiceNo Control, and in my InvoiceNo’s Lostfocus I have following codes almost exact duplicate as before:

Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me.InvoiceNo) Or Me.InvoiceNo = "" Then
strMsg = "You must Enter an Invoice No."
strTitle = "Invoice Number Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.ReffrenceID.SetFocus
Me.InvoiceNo.SetFocus
End If

Bust it does not work and I can navigate or move away from my control, even if there is no Entry.

Could you tell me what is wrong with it?
Also there appears to be another problem, when I want to close my form as we instructed in our ComboBox’s code, If Nothing has been selected and the User decides to close the form, The user would keep getting our MsgBox "You must pick a value from the Bill To list." (Actually this Message appears 3 Times)
1. Why 3 times
2. How can I avoid it? I tried the following codes on Closing, Unload, Lost focus events of my form, But the MsgBox keeps coming.

Me.Combo144.Enabled = False

Best regards,
Sanan
hymn
 
try
docmd RunCommand acCmdUndo
docmd.close

why 3 times because you will have three events that will not let you close the form without data in the combo

can you post all the code for those 2 controls

Hope this helps
Hymn
 
Hi hymn
I am just about to call it quit.
I do not know what are wrongs with these codes, They sometimes work and others in Identical situations or where they supposed to work, They just do not work.

About your comments, There are no other codes basically let’s say the we have the cmbo144 and a textbox called InvoiceNo.
I have the identical codes in both just some adjustments for their names.
Here are all the codes
Private Sub Combo144_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If Me.Combo144.DefaultValue Then
strMsg = "You must pick a value from the Bill To list."
strTitle = "Bill To Customer Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.City.SetFocus
Me.Combo144.SetFocus
Else
Me.InvoiceNo.SetFocus
End If
End Sub

Codes for InvoiceNo
Private Sub InvoiceNo_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me.InvoiceNo) Or Me.InvoiceNo = "" Then
strMsg = "You must Enter an Invoice No. A Date Or Check No.."
strTitle = "Invoice Number Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.ReffrenceID.SetFocus
Me.InvoiceNo.SetFocus
End If
End Sub

My Onload and close Events
Private Sub Form_Open(Cancel As Integer)
Form.UniqueTable = "Tablesales"
DoCmd.GoToRecord , , acNewRec
Me.Combo144.SetFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim strMsg As String, strTitle As String
strMsg = "Entries Are Out Of Balance."
strTitle = "Inventory101"
intStyle = vbOKOnly
If Sd.Value - SC.Value <> 0 Then
MsgBox strMsg, intStyle, strTitle
DoCmd.CancelEvent
End If
End Su

But what is Puzzling is why this code does not work
Private Sub Form_Close()
Me.Combo144.Enabled = False
End Sub
The above does not work for the onload too.

By the way I tried your suggestion, and the following did not work too.
Private Sub Form_Close()
DoCmd.RunCommand acCmdUndo
DoCmd.Close
End Sub
Also in Onload event did not work.

Another strange thing
I tried to introduce a Default value for my combo144 of the value (“”)
Therefore my combo144 has always has the value “” and at the time of closing is no longer Null and then I changed my Combo144 onLost event a little bit which goes as follow:
Private Sub Combo144_LostFocus()
Dim strMsg As String, strTitle As String
Dim intStyle As Integer

If Me.Combo144.DefaultValue Then
Or If Me!combo144 = “” Then
Or If Me.combo144.value =”” then

strMsg = "You must pick a value from the Bill To list."
strTitle = "Bill To Customer Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Me.City.SetFocus
Me.Combo144.SetFocus
Else
Me.InvoiceNo.SetFocus
End If
End Sub
But Nothing works, Now isn’t this really strange, Since The above is Identical codes that used to work before.

Best regards,
Sanan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top