Link to home
Create AccountLog in
Avatar of Travidia
Travidia

asked on

DoCmd OpenForm - Opening without Add ability

I have an button on a form that opens another form.  The form is a Datasheet view and allows Add and Delete of records.  When I use this command, I can't add records when the form opens.  Please correct the code to allow the form to open with the Add record ability: DoCmd.OpenForm "frmTasks",acFormDS

Thanks a lot!
Scott
Avatar of Eric Sherman
Eric Sherman
Flag of United States of America image

Try this ...

1.) Open just the Record Source (Table or Query) of the frmTasks form and see if you can Add records.

2.) If so, then try this  DoCmd.OpenForm "form1", acFormDS, , , acFormEdit

ET
Avatar of Travidia
Travidia

ASKER

Hey ET,

OK, I have a query as the source on my form:

SELECT tblTasks.Department, tblTasks.TaskID, tblTasks.TaskDescription, tblTasks.Management FROM tblTasks WHERE (((tblTasks.Management)=fn_get_user_name())) ORDER BY tblTasks.TaskID;

When I open the query and run, it won't let me add records.  Why is this?  I thought if my query only had  one table and no joins that I would be able to edit it like a table.    Please help.
fn_get_user_name()

Can you post the code for this ... just in case.

mx
on the form property sheet check the setting of
Recordset Type .... be sure it is NOT Snapshot ... same on your query properties ...

mx
RecordType on both query and form are set to Dynaset.

Code for UName:

Option Compare Database

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function fn_get_user_name() As String

'Returns the network ID of the person that logged into the machine that is running this Access application:
'This is not the same as the Access security user.

'Visual Basic Source Code Library, The Waite group, Chapter 12.5

On Error GoTo err_fn_get_user_name

Dim str_user_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_user_name = Space(80)
lng_buffer_size = Len(str_user_name)

lng_ret_code = GetUserName(str_user_name, lng_buffer_size)

lng_null_character_position = InStr(str_user_name, Chr(0))
If lng_null_character_position > 0 Then
    str_user_name = Left(str_user_name, lng_null_character_position - 1)
Else
    str_user_name = " "
End If

fn_get_user_name = UCase(str_user_name)

exit_fn_get_user_name:
    Exit Function
   
err_fn_get_user_name:
    fn_get_user_name = "Not able to get user name."
    Resume exit_fn_get_user_name
   
End Function
Is it possible that some or all of the fields are locked and/or disabled?

"thought if my query only had  one table and no joins that I would be able to edit it like a table."
You are correct ... there does not appear to be anything wrong with the query ... unless possibly the
Recordset Type got changed to Snapshot

mx

ASKER CERTIFIED SOLUTION
Avatar of Eric Sherman
Eric Sherman
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I'm not quite sure whether you can't add records, edit records or can't do either.

You should check the form properties for AllowEdits and AllowAdditions to make sure they are set to Yes.
Hmm.  
first I tried - only showing three of the fields in the table in my query.  It wouldn't let me add records.  
then I changed the results to * and it would allow me to add records.  
Function seems ok ... doesn't appear to modify the form in any way ...

As usual ... everything 'looks' ok ...

can you upload to http://www.ee-stuff.com/Expert/Upload/upload.php ... removing any sensitive data of course?  

Then, provide me the link EE-Stuff gives you to the file location ... back here in this thread.

Note: There is a  4MB upload limit.

mx
OK, now that I have * selected, I can add my criteria back and it still works.  Thanks ET.
Any reasoin why it wouldn't let me add records if I only have certain fields selected instead of *?
>>>>OK, now that I have * selected, I can add my criteria back and it still works.  Thanks ET.<<<<

I ran into the same problem a few weeks ago with an application I migrated the back-end tables to MySQL.  All of the data entry forms in the front-end would not allow me to add records until the Unique ID Primary Key field was included in the Record Source of the form.  Conversions ....Arggggggggggggg

ET
Are there relationships set up on that table?

Are you getting errors?  What exactly is happening?

mx
No Relationships.  I did exactly the same - imported from Access to SQL.  Strange limitation/restriction.  Thanks for the great solution ET.