cmdButton to Open Form at New Record

gyli84

Registered User.
Local time
Today, 20:23
Joined
Aug 8, 2001
Messages
25
As part of a helpdesk system I want users to be able to log calls. I have a helpdesk staff switchboard and as part of it I want a button that when clicked will direct the user to a NEW RECORD in a form called "Calls". I think this might have something to do with the DataEntry property in VB. I tried creating a command button using a wizard and then adding DataEntry = True but it didn't work. Does anyone know how to code such a button or what to add to a wizard button code or to specify as the criteria for an OpenForm macro which will do this?

Also, does anyone know how I can get data in a textbox to be dynamic and saved (ie. if you open a form and enter a value in it it will remain there when it is closed) without setting it as the control source or default value of the textbox (then if you update it from the form view the value isn't saved) or linking it to a value in a table? I have a procedure that looks at the value in that textbox and if another value is greater it changes the colour of other controls etc. The value in the textbox I am talking about must be updatable and can't have a default value.

Thanks!
 
Quick answer to question 1. Search Help for OpenForm method. The answer is there....
 
I'm not sure if this is what you're talking about, but here goes. You can create custom database properties which are persistent (i.e., stored in the database when it's closed) yet are not stored in any table. The following code provides routines for setting, retrieving and deleting such properties.

Option Compare Database
Option Explicit
Function SetCustomProperty(PropName As String, PropType As Integer, PropValue As Variant) As Boolean
'Attempts to set the value of a custom (user-defined) property in the current database, first
'creating that property if necessary; returns True if operation is successful, or False if not;
'if PropValue is Null or an empty string, DelCustomProperty will be called to delete the property
Dim dbs As Database, Cnt As Container, doc As Document, prp As Property
Const conPropertyNotFound = 3270 'define constant for Property not found error
On Error GoTo SetCustomProperty_Err
If IsNull(PropValue) Or PropValue = "" Then
SetCustomProperty = DelCustomProperty(PropName)
GoTo SetCustomProperty_End
End If
Set dbs = CurrentDb 'define Database object
Set Cnt = dbs.Containers!Databases 'define Container object
Set doc = Cnt.Documents!UserDefined 'define Document object
doc.Properties.Refresh
'Set custom property name. If error occurs here it means
'property doesn't exist and needs to be created and appended
'to Properties collection of Document object.
Set prp = doc.Properties(PropName)
prp = PropValue 'Set custom property value
SetCustomProperty = True
SetCustomProperty_End:
Exit Function
SetCustomProperty_Err:
If Err = conPropertyNotFound Then 'Property not found error
Set prp = doc.CreateProperty(PropName, PropType, PropValue)
doc.Properties.Append prp 'Append to collection
Resume Next
Else 'Unknown error
SetCustomProperty = False
Resume SetCustomProperty_End
End If
End Function
Function GetCustomProperty(PropName As String) As Variant
'Attempts to read a custom (user-defined) property from the current database;
'returns property's value if successful, or Null otherwise
Dim dbs As Database, Cnt As Container, doc As Document, prp As Property
Const conPropertyNotFound = 3270 'define constant for property not found error
On Error GoTo GetCustomProperty_Err
Set dbs = CurrentDb 'define Database object
Set Cnt = dbs.Containers!Databases 'define Container object
Set doc = Cnt.Documents!UserDefined 'define Document object
doc.Properties.Refresh
GetCustomProperty = doc.Properties(PropName)
GetCustomProperty_End:
Exit Function
GetCustomProperty_Err:
GetCustomProperty = Null
Resume GetCustomProperty_End
End Function
Function DelCustomProperty(PropName As String) As Boolean
'Attempts to delete a custom (user-defined) property from the current database;
'returns True if operation is successful, or False if property not found or other error
Dim dbs As Database, Cnt As Container, doc As Document
On Error GoTo DelCustomProperty_Err
Set dbs = CurrentDb 'define Database object
Set Cnt = dbs.Containers!Databases 'define Container object
Set doc = Cnt.Documents!UserDefined 'define Document object
doc.Properties.Delete PropName
DelCustomProperty_End:
DelCustomProperty = True
Exit Function
DelCustomProperty_Err:
DelCustomProperty = False
End Function
 
Re: Opening your form at a new record
Add this code to the click event of your command button.

DoCmd.OpenForm ("Calls")
DoCmd.GoToRecord acDataForm, "Calls", acNewRec
 

Users who are viewing this thread

Back
Top Bottom