Clear/Replace Default Value On GotFocus/LostFocus

Mar 24, 2005

I have a table with three fields that have a default value set ("Please Provide"). I have controls for these fields on a form, and procedures for the GotFocus and LostFocus events.

GotFocus:
Code:Private Sub cpuSerial_GotFocus()If Me.cpuSerial.Value = Me.cpuSerial.DefaultValue ThenMe.cpuSerial.Value = ""End IfEnd Sub

LostFocus:
Code:Private Sub cpuSerial_LostFocus()If IsEmpty(Me.cpuSerial.Value) = True ThenMe.cpuSerial.Value = Me.cpuSerial.DefaultValueEnd IfEnd Sub

The intention here is to clear the default value when the user clicks into the field, but replace the default value if the field is empty when the user leaves - not altering the control contents at all if the user entered his own data. The end result is that there aren't records where this field is empty - it is either a user-entered value, or the default value.

My VB is not great - but this seems like a fairly rudimentary thing to accomplish, and what I have SHOULD work. But if that were the case, I wouldn't be writing this.

I suspect I might be misusing the DefaultValue property, or maybe the "Please Provide" default value property is better set on the form rather than in the table...

View Replies


ADVERTISEMENT

Modules & VBA :: How To Get GotFocus And LostFocus Of All Comboboxes

Feb 20, 2015

how I can get GotFocus and LostFocus of all comboboxes. See below the three codes (code 1, 2 and 3) that I've change from an example from the internet. But the problem is that the function "InitialiseEvents" is not running in these comboboxes. If I try the code 4 as an example, the function "InitialiseEvents" is running perfectly. I don't understand why I can't get GotFocus and LostFocus? You can to see two attachments:

Afbeelding1: The codes 1, 2 and 3 are running.
Afbeelding2: The codes 1, 2 and 4 are running.

Code 1:

Code:
Private Sub Form_Open(Cancel As Integer)
InitialiseEvents Me
End Sub

Code 2:
Code:

Public Function InitialiseEvents(frm As Access.Form)
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If .ControlType = acComboBox Then
.OnGotFocus = "=HandleFocus('" & frm.Name & "', '" & .Name & "', 'Got')"

[code]...

View 7 Replies View Related

Find And Replace Default Settings

Dec 22, 2005

Is there any way to change the default settings on the Find and Replace dialog from 'Whole field' to 'Any part of field'?

Thanks very much in advance.

Rob

PS Happy Christmas!!

View 5 Replies View Related

Subform Control Lostfocus

Aug 9, 2005

I've use a set up that works fine on a form but doesn't when used in a subform. Basically, i have a check box and txt box that won't allow anything to be written in it unless the check box is checked. If it is checked and nothing is inputted in the text box, the lostfocus event for the txt box flags the user. It works fine in a normal form and when it's a subform, the lostfocus event does fire when going to another control in the subform. The problem is that it doesn't fire when going to another control not in the subform. Is there anyway I can get the lost focus event to fire under these circumstances?

Thanks,

scratch

View 1 Replies View Related

Error Handling When LostFocus Doesn't Work

Jun 7, 2006

Hi, hope somebody can help with this problem.

I have a med-large db shared on network. Am under some pressure to split front/back so more people can do data entry, but want the forms to be semi-finished before putting them on everybody's c:drive.

The problem is error handling for required fields. Some fields are required in the underlying tables because if users don't fill them in, reports are useless. But Access error msg for required fields are too strange, users just close down, maybe wrecking the thing. Don't want to eliminate Close button yet in case they get stuck in Access hell.

I got one ( !! ) field locked in well using LostFocus event, but what do you do if users just mouse into fields at random? LostFocus won't work if it never had focus, right?

(Would much prefer to just use unbound form and give choice of "Field is required" and "OK" or "Cancel this record" but realize that's asking for a lot of help here.)

Any assistance you can offer would be MUCH appreciated!! Vba course isn't until July.

Thanks,

View 9 Replies View Related

Queries :: Make Replace Query To Look In Order To Find What To Replace

May 6, 2014

I have this working query:

Code:
INSERT INTO TB_SISTEMAS ( LOGIN, SISTEMA, PERFIL, DATA )
SELECT Left([dbo_BACKUP_ACESSOS.LOGIN],255) AS LOGIN, dbo_BACKUP_ACESSOS.SISTEMA, Left([dbo_BACKUP_ACESSOS.PERFIL],255) AS PERFIL, dbo_BACKUP_ACESSOS.DATA
FROM dbo_BACKUP_ACESSOS
WHERE (((dbo_BACKUP_ACESSOS.SISTEMA)<>"ACTIVE DIRECTORY") AND ((dbo_BACKUP_ACESSOS.DATA)="2014-03-23"));

But Iwant to be able to use a set of data to be used in the Replace Statement, so I create a table to add each string I would like to have replaced by "nothing", and trying to make the replace query to look there in order to find what to replace.I also created a table where I will list the systems that I dont want in the select, so I removed the "ACTIVE DIRECTORY" and replaced by the colum that have the list of system I dont want listed.This is the result:

Code:
INSERT INTO TB_SISTEMAS ( LOGIN, SISTEMA, PERFIL, DATA )
SELECT Replace((Left([dbo_BACKUP_ACESSOS.LOGIN],255)),[PREFIXOS_E_SUFIXOS]![Valor],"") AS LOGIN, dbo_BACKUP_ACESSOS.SISTEMA, Left([dbo_BACKUP_ACESSOS.PERFIL],255) AS PERFIL, dbo_BACKUP_ACESSOS.DATA
FROM dbo_BACKUP_ACESSOS
WHERE (((dbo_BACKUP_ACESSOS.SISTEMA)<>[SISTEMAS_EXCLUIDOS]![Sistema]) AND ((dbo_BACKUP_ACESSOS.DATA)="2014-03-23"));

The thin is that this keeps asking me to enter the parameter value for "PREFIXOS_E_SUFIXOS!Valor" and for "SISTEMAS_EXCLUIDOS!Sistema"

View 6 Replies View Related

Default Combo Box Based On Default Table Value

Feb 13, 2006

Hi Everyone,

I hope someone can help.

I have a form with a combo boxes and a table with relevant list and additional field, fldDefaultDrive (Yes/No Field).

Currently in order to set the default value, I have used the following code for each default;

Private Sub Form_Load()
Forms!frmMediaLabeller!CboDriveName.DefaultValue = """D"""

End Sub

However, I want users to be able to go into the table and change the default value if thier CD player default Drive is anything but D: Drive. I have tried to replace the D above with an SQL statement but with no success.

Private Sub Form_Load()

Dim Drivename As String

Drivename = SELECT tblMediaDrive.fldDrivename FROM tblMediaDrive WHERE (((tblMediaDrive.fldDefaultDrive)=-1));

Forms!frmMediaLabeller!CboDriveName.DefaultValue = """Drivename"""

End Sub

This is definetly not working, can anybody help, I have a feeling it is syntax but not sure where? :confused:

Robert88

View 7 Replies View Related

Clear A Combo Box

Jan 13, 2006

what's the best way of clearing the contents of a combo box? i don't want to change the row source, just make it blank as though a selection has not been made.

i have two unrelated combo boxes on a form; there will probably be more later. when i pick a value from one i want the other(s) to clear.

on the after update event of each combo i've tried clearing the contents of the other combo with these:

- me.othercombo = null
- me.othercombo = 0
- me.othercombo = ""
- me.othercombo.value = ...
- me.othercombo.undo
- etc.

'= null' clears the other combo.
'= 0' also clears the other combo.

but i think i'm missing something here. each combo also has a cmdbutton that will take the user to another form based on the selection made.

if i use '= 0', the other combo clears but its cmdbutton still works. even if the combo appears to be empty its associated cmdbutton still opens the next form (it should produce a msgbox asking the user to make a selection).

'= null' clears the combo and its cmdbutton produces the appropriate message to make a selection. so that's what i'm using right now. is this the best way? can something = null?

View 3 Replies View Related

What Is Best Way To Clear Tables?

Apr 2, 2007

I need to b able to clear records from 3 tables with one click

I tried opening each as a record set and looping through deleting each in turn with a loop, however this I know to be poor practice and it also errors as i cannot delete a record that is part of a relationship.

is there a more suitable way to do this?

View 9 Replies View Related

Clear All Values Except N/A

Feb 10, 2008

Hi:

I have a table setup to enter dates for each person that requires safety quizes for the month those that don't have an "N/A" for the month by thier names.

Each year I have to start over and it is a real pain to manualy delete all the dates for each person for Jan through December.
I only want the dates gone not the name or the N/A values.

Is there a sub or query that will search each record and only delete the dates?

Thanks
Charles

View 14 Replies View Related

Clear A Listbox???

Feb 21, 2005

I'm using access 2003, and for some stupid reason they decided to remove the "clear" method from listboxes... In previous access version I could clear a listbox using "listbox.clear", but now I have no idea. Does anyone know a good way to clear listboxes in Access 2003.

View 4 Replies View Related

Clear A Form

Apr 12, 2005

Hey all,

I have some code that looks like this to control a form;

Private Sub btnAdd_Click()
Dim UserName As String
Dim Initials As String
Dim Password As String
Dim OutlookName As String
Dim rst As DAO.Recordset

'Check each control, is their a value? if not, set focus to control
If IsNull(txtUserName) Then
MsgBox "You did not enter a new UserName nobby!"
Me!txtUserName.SetFocus
Exit Sub

ElseIf IsNull(txtInitials) Then ' return value of UserName variable;
MsgBox "You have not entered any initials for user: '" & Me!txtUserName & "'"
Me!txtInitials.SetFocus
Exit Sub

ElseIf IsNull(txtPassword) Then
MsgBox "You must create a password for user: '" & Me!txtUserName & "'"
Me!txtPassword.SetFocus
Exit Sub

ElseIf IsNull(txtOutlookName) Then
MsgBox "You must enter a Outlook name for: '" & Me!txtUserName & "'"
Me!txtOutlookName.SetFocus
Exit Sub

End If
' Pass the variables to the table.
Set rst = CurrentDb.OpenRecordset(("Users"), dbOpenDynaset, [dbSeeChanges])
With rst
.AddNew
![User] = Me!txtUserName
![Password] = Me!txtPassword
![Initials] = Me!txtInitials
![OutlookName] = Me!txtOutlookName
![Level] = 1
![Select] = 0
![dummy] = Null
.Update
.Close
Set rst = Nothing
End With
DoCmd.Close
End Sub

Private Sub btnCancel_Click()
' Confirm Cancellation Box
If MsgBox("Are you sure you want to quit?", vbYesNo, "Caution") = vbYes Then
DoCmd.Close
Else
DoCmd.CancelEvent
End If

End Sub

What I really want to do is once the update has occured is set a label I have as hidden, to show and to clear all the controls.

View 5 Replies View Related

Clear The Form

Jun 5, 2005

Thanks,
Now I can populate text fields by selecting any one of the combo box selection.

But I need to clear the form to insert next record. Currently I am inserting record by using Save_cmd button. I can insert second record but couldnot clear all the fields after inserting automatically. So I am doing clear all the fields manually or overwriting values.

If there is anyone pl. help me.

Thanks

View 2 Replies View Related

Clear Up Value On Next Record

Feb 16, 2006

Hi everyone

I have a part of the form with the following fields

Title
Name
Address1
Address2
Area
...

Address2(street) field is a drop downbox, once selected the area text field will be automatically shown
what I got in AfterUpdate event on Street is as below
Me.txtArea = [cboAddress2].[Column](2)

the problem with this is, even when I move to another record the Area field doesn't clear up which is still using the old Area info that has been selected before,

I belive I have to have some Clear Up function on somewhere, not sure exactly where and what Code will clear up the value,

Can anyone help please!!

Thanks in advance
Si

View 1 Replies View Related

Clear Form

May 5, 2006

Hello,

I would like to put a button on a form I am making so that you can clear it without saving the data.

eg you open the form input a load of data, it is all wrong so you click clear form and start inputting data again

I have the button what do i need to do to get it to do this

Thanks

Chris

View 4 Replies View Related

Clear Button

Nov 15, 2006

i have a form that allows to add details to the table "tab_main".

ive got a clear button, it clears all textboxes apart from the textbox "date_issued". i get the following error message:

'Run-time error '2113':

The value you entered isn't valid for this field.'

Why am i getting this?

ive checked the table field and im inputting the right value!

in the command button under EVENT PROCEDURE, im using following code:


Private Sub Command25_Click()

Dim intResponse As Integer

intResponse = MsgBox("Are you sure you want to clear the text Boxs", vbYesNo, Change)

If intResponse = 6 Then
Me.number.Value = " "
Me.username.Value = " "
Me.cost_centre.Value = " "
Me.phone_model.Value = " "
Me.imei.Value = " "
Me.sim_no.Value = " "
Me.puk_code.Value = " "
Me.date_issued.Value = " "

Else

End If

End Sub

Help me!!!! thanks

View 4 Replies View Related

Clear Form

Mar 7, 2006

I have a SQL Database that is housing my tables
I have an Access Front end that is Allowing users to view and edit the data residing on the SQL Database.

I have write/modify rights on the database and as such I wrote the code , OnLoad of Form, to Automatically set the Form to "Add Record", thus clearing all the TextBoxes and ComboBoxes. That works alright.

My problem is when a user without write/modify rights opens the Form I am getting an Error "Cannot go to specified Record". If I understand this right this is happening because they do not have suffeciant rights.

How Can I get a form to load and display all the textboxes and ComboBoxes BLANK....this only way I can think of is to set the form to Add Record.

ANY THOUGHTS

View 2 Replies View Related

HELP ! How To Clear A Filter ..................

Jun 14, 2006

hi,

How do I clear a filter ? When I re-open a form that is based on a stored parameter query, I get a message about "apply/filter that cannot be applied..."

So, as a result, I put in some code for that command button that closes the form, then reopens it, and I get my prompt from the query. Isnt there a way to clear the filter without closing the form? It looks funny to me and I know the users will have a cow. I sure appreciate any ideas.Im digging around to see what I can do quickly, but I cant find anything that works. thanks a lot!

View 3 Replies View Related

Clear On RecordsetChange

Jul 19, 2006

Private sub Form_DatasetChange()
Text28.Text.Clear
End Sub

I am wanting to move between records but when I return to the records I have just moved from I want to clear some of the text boxes. This code is not working though. Any suggestions

View 2 Replies View Related

Clear List Box?

Feb 28, 2007

Where is the ListBox.Clear option??????

How can I clear the entire ListBox?

View 4 Replies View Related

Clear Out A Table To Add New Records

Jan 31, 2006

I have a transfertext macro that imports my text file into a table but the table already has data in it so it is not importing and losing all the records. What do i do to clear out the table before i import in.. Can i use another macro ???

View 1 Replies View Related

Clear Login UserName

Jul 18, 2006

Hi all,

I've had a quick search but couldn't find the answer to this.

Is there a way that when a user launches the application via my workgroup file, the default login name is always null?

Currently it retains the last users' login name.

Thanks
Kempes

View 6 Replies View Related

Clear Range Of Data

Jul 12, 2005

Is it possible to clear the cotents from various records but only the values in one column. Like let's say I just want the delete the values in the Price column for a range of about 6000 records. Not the whole records just those price values.

I can't seem to find a way to do this without sitting there and pushing down and backspace over and over again.

thanks,
joëlle

View 1 Replies View Related

A Way To Clear The Tables In The Database...

Jul 19, 2006

Thanks for considering my question. I have developed a DB with about 60 tables, all related by one-to-many relationships. During development, I placed values in the tables, generated keys, etc. so things have gotten quite cluttered. Is there a way (vb program, access method, etc.) that I can use to remove all the entries from the table, and essentially start with a set of clean tables and no keys? I'd like to be able to run this from a control on a form.

View 2 Replies View Related

SQL To Clear Multiple Tables

Sep 13, 2005

I am currently using this Query to delete all records in Table x:
Delete * From x;

Then repeating similar for Table y, then Table z, etc


I would like to delete all records from multiple Tables in a single step, e.g.:
DELETE x.*, y.*, z*
FROM x, y, z;

I get an error message "could not delete from specified tables". Could anyone tell me where where I am going wrong?

Thanks

k

View 4 Replies View Related

Clear Search Results

Jun 28, 2005

I created a search form (using code from here) that searches serveral fields and displays the results in a listbox. I also created a clear button to clear the fields, including the listbox. I can search all day and it works fine, and the CLEAR button clears out the fields fine but once I have clicked the CLEAR button, I cannot search anymore. I don't get any results anymore (until I close and reopen). It must be something simple that I am overlooking so any hints would be appreciated.
Here is my code (sorry it's long!):


Private Sub cmdClearForm_Click()
On Error GoTo Err_cmdClearForm_Click

Dim I As Integer

' Cycle through the form's controls, testing for text,
' and clear each field.
For I = 0 To Me.Count - 1
If TypeOf Me(I) Is TextBox Then
Me(I) = ""
ElseIf TypeOf Me(I) Is ListBox Then
Me(I).RowSource = " "
End If
Next

Me.txtMacAddr1.SetFocus

Exit_cmdClearForm_Click:
Exit Sub

Err_cmdClearForm_Click:
MsgBox Err.Description
Resume Exit_cmdClearForm_Click

End Sub
Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click

Dim strSQL As String, strOrder As String, strWhere As String, strOrderChoice As String
Dim db As DAO.Database
'Dim qryDef As QueryDef
Set db = CurrentDb()

strSQL = "SELECT tblAsset.MacAddr1, tblAsset.SerialNum, tblIPAddresses.IPAddress,tblIPAddresses.HostName, tblLocation.JackNumber, tblLocation.CircuitID, tblLocation.Department,tblLocation.SpecificLoc, tblLocation.User, tblLocation.Building, tblLocation.RoomNumber " & _
"FROM tblAsset, tblIPAddresses, tblLocation " & _
"WHERE tblAsset.AssetNum=tblIPAddresses.AssetNum and tblAsset.AssetNum=tblLocation.AssetNum"

strWhere = " and "
strOrder = "order by"
strOrderChoice = "tblLocation.Department"

If Not IsNull(Me.txtMacAddr1) Then
strWhere = strWhere & "(tblAsset.MacAddr1) like '*" & Me.txtMacAddr1 & "*' and "
strOrderChoice = "tblAsset.MacAddr1"
End If

If Not IsNull(Me.txtMacAddr1) Then
strWhere = strWhere & "(tblAsset.MacAddr2) like '*" & Me.txtMacAddr1 & "*' and "
strOrderChoice = "tblAssest.MacAddr2"
End If

If Not IsNull(Me.txtSerialNum) Then
strWhere = strWhere & "(tblAsset.SerialNum) like '*" & Me.txtSerialNum & "*' and "
strOrderChoice = "tblAsset.SerialNum"
End If

If Not IsNull(Me.txtIPAddress) Then
strWhere = strWhere & "(tblIPAddresses.IPAddress) like '*" & Me.txtIPAddress & "*' and "
strOrderChoice = "tblIPAddresses.IPAddress"
End If

If Not IsNull(Me.txtHostName) Then
strWhere = strWhere & "(tblIPAddresses.HostName) like '*" & Me.txtHostName & "*' and "
strOrderChoice = "tblIPAddresses.HostName"
End If

If Not IsNull(Me.txtJackNumber) Then
strWhere = strWhere & "(tblLocation.JackNumber) like '*" & Me.txtJackNumber & "*' and "
strOrderChoice = "tblLocation.JackNumber"
End If

If Not IsNull(Me.txtCircuitID) Then
strWhere = strWhere & "(tblLocation.CircuitID) like '*" & Me.txtCircuitID & "*' and "
strOrderChoice = "tblLocaton.CircuitID"
End If

If Not IsNull(Me.txtBuilding) Then
strWhere = strWhere & "(tblLocation.Building) like '*" & Me.txtBuilding & "*' and "
strOrderChoice = "tblLocation.Building"
End If

strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
Me.lstResults.RowSource = strSQL & " " & strWhere & " " & strOrder & " " & strOrderChoice

db.Close

Exit_cmdSearch_Click:
Exit Sub

Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click

End Sub

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved