Help pls - error on code and I dont know how to fix :)

A

azu_daioh

I have a form for data entry only with 2 controls "initials" and
"notesEntry"
On the main form, there is a link to open the above form
[frm_Logs_NotesEntry] and on the [frm_Logs_NotesEntry] form is a
button to transfer the notes entered to the main form's subform


I will have mutliple forms using the [frm_Logs_NotesEntry] for data
entry and on each form the subform is standard name
sfrm_NAMEOFMAINFORM_NotesOnly.

Here's the code:
Private Sub enterNotes_Click()
Dim xNotes As String
Dim xInitials As String
Dim xDate As Date
Dim yNotes As String


xDate = Date
xNotes = Me.notesEntry
xInitials = Me.Staffinitials


yNotes = xDate & ": " & xNotes & " //" & xInitials

DoCmd.Close acForm, "frm_Logs_NotesEntry"

Dim frmCurrentForm As Form
Dim frmName As String
Dim sfrmName As String
Dim ctlName As String


Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
sfrmName = "sfrm_" & frmName & "_NotesOnly"
ctlName = frmName & "." & sfrmName & ".Form." & "LogEntry"

ctlName = yNotes & vbCrLf & vbCrLf & ctlName


End Sub
-----------------------

For example if my main referrals forms =
[frm_IDReferrals], my subform would be named
[sfrm_frm_IDReferrals_NotesOnly]
[frm_ATRefferals], my subform would be named
[sfrm_frm_ATReferrals_NotesOnly]

on each form above, I'm calling the [frm_Logs_NotesEntry] for data
entry and the notes would be then entered on a memo control for each
subform called [LogEntry].

Is there a way to accomplish this without creating a separate
[frm_Logs_NotesEntry] form for each main referrals form?

The above code gives "Type mismatch" error message.
I obviously don't know what I'm doing so please help me out :)

This is the form I had before that worked:
Dim frmCurrentForm As Form

Set frmCurrentForm = Screen.ActiveForm

frmCurrentForm.sfrm_frm_IDReferralsLog_NotesOnly.Form.LogEntry =
yNotes _
& vbCrLf & vbCrLf _
&
Forms.frm_IDReferralsLog.sfrm_frm_IDReferralsLog_NotesOnly.Form.LogEntry


Thank you,
Sharon
 
J

John W. Vinson

I have a form for data entry only with 2 controls "initials" and
"notesEntry"
On the main form, there is a link to open the above form
[frm_Logs_NotesEntry] and on the [frm_Logs_NotesEntry] form is a
button to transfer the notes entered to the main form's subform


I will have mutliple forms using the [frm_Logs_NotesEntry] for data
entry and on each form the subform is standard name
sfrm_NAMEOFMAINFORM_NotesOnly.

Here's the code:
Private Sub enterNotes_Click()
Dim xNotes As String
Dim xInitials As String
Dim xDate As Date
Dim yNotes As String


xDate = Date
xNotes = Me.notesEntry
xInitials = Me.Staffinitials


yNotes = xDate & ": " & xNotes & " //" & xInitials

DoCmd.Close acForm, "frm_Logs_NotesEntry"

Dim frmCurrentForm As Form
Dim frmName As String
Dim sfrmName As String
Dim ctlName As String


Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
sfrmName = "sfrm_" & frmName & "_NotesOnly"
ctlName = frmName & "." & sfrmName & ".Form." & "LogEntry"

ctlName = yNotes & vbCrLf & vbCrLf & ctlName


End Sub


What line gives the error? If you step through the code line by line, what is
the value of ctlname? WHY are you setting ctlName twice?

John W. Vinson [MVP]
 
A

azu_daioh

Thanks John. I thought I responded to this earlier when I found out
the solution. I hope it didnt get posted someplace else. :)

You were right, i realized I was setting ctlName twice and did a
search in the forum and found the correct syntax when referencing a
form using string expression. Here's the code I finally got to work:

Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
sfrmName = "sfrm_" & frmName & "_NotesOnly"

frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry") =
yNotes _
& vbCrLf & vbCrLf &
frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry")
 
A

azu_daioh

I figured it out -- searched the forum using "reference form using
string expression"

here's the code:
Dim xNotes As String
Dim xInitials As String
Dim xDate As Date
Dim yNotes As String


xDate = Date
xNotes = Me.notesEntry
xInitials = Me.Staffinitials


yNotes = xDate & ": " & xNotes & " //" & xInitials

DoCmd.Close acForm, "frm_Logs_NotesEntry"

Dim frmCurrentForm As Form
Dim frmName As String
Dim sfrmName As String


Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
sfrmName = "sfrm_" & frmName & "_NotesOnly"

frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry") =
yNotes _
& vbCrLf & vbCrLf &
frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry")
 
A

azu_daioh

Thanks John. I thought I responded to this earlier when I found out
the solution. I hope it didnt get posted someplace else. :)

You were right, i realized I was setting ctlName twice and did a
search in the forum and found the correct syntax when referencing a
form using string expression. Here's the code I finally got to work:

Set frmCurrentForm = Screen.ActiveForm
frmName = frmCurrentForm.Name
sfrmName = "sfrm_" & frmName & "_NotesOnly"

frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry") =
yNotes _
& vbCrLf & vbCrLf &
frmCurrentForm.Controls(sfrmName).Form.Controls("LogEntry")
 

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