UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Data Type Conversion Error In Public Sub, Access 2016    
 
   
Ceebaby
post Jan 19 2020, 05:29 PM
Post#1



Posts: 22
Joined: 17-October 18



Hi Everyone

I hope someone can help me. I have created a public subroutine to insert a new task record on a table called tbltasks. This is used to alert employees they have a new HR task. I moved it from a private sub which works but now as a public sub I keep getting a data type conversion error. I want to be able to use a form's fields to populate the sub but cannot work out how to get public sub to accept a text string such for me!employmentID which returns an integer value

I hope this makes sense

Any help would be truly appreciated. Here is my code.

Public Sub AddTaskAlert(TskByID As String, tskType As Integer, relateID As Integer, relatedesc As String, Optional AuthorID As integer, Optional tskGroup As Integer)
On Error GoTo procErr

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("tblUserTasks", , dbAppendOnly)

With rs
.AddNew
![tskEmploymentID] = TskByID ("this is a PK field which on the form is me!txemploymentID how do I pass this string to the sub?)
![TaskTypeID] = tskType
![tskGroupID] = tskGroup
![TaskForID] = AuthorID
![DateReceived] = Now()
![RelatedID] = relateID
![RelatedDesc] = relatedesc
.Update
End With

rs.Close
Set rs = Nothing

AddTaskAlert_Exit:

Exit Sub

procErr:
Call LogError(Err.Number, Err.Description, "AddTaskAlert Function")
Resume AddTaskAlert_Exit

End Sub


Any help would be truly appreciated.
Ceebaby iconfused.gif

Go to the top of the page
 
theDBguy
post Jan 19 2020, 05:35 PM
Post#2


UA Moderator
Posts: 77,524
Joined: 19-June 07
From: SunnySandyEggo


Hi. If the field in the table is a number, then maybe you should also pass a number to the subroutine, instead of a string.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
Ceebaby
post Jan 19 2020, 05:44 PM
Post#3



Posts: 22
Joined: 17-October 18



Thanks DB guy for your response. I have tried converting this to an integer but still getting the error message.
Is there no way to pass a forms field value to the sub?

I am self taught and thought I had this nailed but it has me stumped.

Cheers for any further help.
Go to the top of the page
 
Ceebaby
post Jan 19 2020, 05:45 PM
Post#4



Posts: 22
Joined: 17-October 18



Sorry I mean the name of the control on the form and its underlying field
Go to the top of the page
 
June7
post Jan 19 2020, 05:55 PM
Post#5



Posts: 1,241
Joined: 25-January 16
From: The Great Land


Step debug. Does TskById have correct value? Did you change procedure to declare this variable as Integer?

Is tskEmploymentID an integer field for saving a PK from parent record?


--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
Ceebaby
post Jan 19 2020, 05:57 PM
Post#6



Posts: 22
Joined: 17-October 18



Sorted it out - it was the way I was calling the sub.
Removed call on the sub and retyped tsktypeID as integer and it worked.

Thanks for the steering me in the right direction Mr DBGuy and have a good evening.
Cheers
Ceebaby
Go to the top of the page
 
Ceebaby
post Jan 19 2020, 05:59 PM
Post#7



Posts: 22
Joined: 17-October 18



Thanks for your response - yet mis-typed integer and removed call from the sub routine.
Cheers
Ceebaby
Go to the top of the page
 
Ceebaby
post Jan 19 2020, 05:59 PM
Post#8



Posts: 22
Joined: 17-October 18



Thanks for your response - yet mis-typed integer and removed call from the sub routine.
Cheers
Ceebaby
Go to the top of the page
 
theDBguy
post Jan 20 2020, 12:47 AM
Post#9


UA Moderator
Posts: 77,524
Joined: 19-June 07
From: SunnySandyEggo


Hi. Glad to hear you got it sorted out. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    24th February 2020 - 07:42 PM