Problem adding record from form (1 Viewer)

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
Hi guys, Having a bit of trouble with a command button on a form.

I want it to take info entered in a form "Call Logging" and add it to a table "Calls" but it just doesn't wan to work :( . My current code is:
-----------------------------------------------------------------------
Private Sub Log_Call_Button_Click()

Dim StrMsg As String
Dim intRespons As Integer
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Call Logging"

stLinkCriteria = "[Company]" & Me![Company name]
DoCmd.OpenForm stDocName, , , stLinkCriteria = "[Company]1"
DoCmd.GoToRecord , , acNewRec

StrMsg = "You are about to add a new call to the database:" & vbNewLine & "" & vbNewLine & ""
StrMsg = StrMsg & "Proceed?"
intRespons = MsgBox(StrMsg, vbInformation + vbYesNo)

With Tables![Calls]

If intRespons = vbNo Then
DoCmd.RunCommand acCmdClose
Exit Sub
End If

If .NewRecord Then
.Company_name = Me.[Company]
.Call_Status = Me.[Call Status]
.Engineer = Me.[Engineer]
.Date_Received = Me.[Date Received]
.Job_Description = Me.[Call Descrpition]
.Job_Solution = Me.[Solution Description]
End If
End With

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

The error that comes up says "Runtime Error 424: Object required" and "With Tables![Calls] is highlighted so guess that's where the problem is but i can't get it lol any help would be greatly appreciated, I've been working on this for too long lol :eek:
 

DCrake

Remembered
Local time
Today, 15:57
Joined
Jun 8, 2005
Messages
8,632
These two lines look suspect to me

stLinkCriteria = "[Company]" & Me![Company name]
DoCmd.OpenForm stDocName, , , stLinkCriteria = "[Company]1"

firstly I assume that the field Company is a text field, therefore the Me![Company name] should be surrounded in quotes

Code:
stLinkCriteria = "[Company] = '" & Me![Company name] & "'"

Also using a company name as a link criteria is also suspect as you may have more than one company with the same name. You should be using PK's as criteria.

secondly the "[Company]1" looks syntactically incorrect.

Also you are applying a criteria to the form filter then issuing a go to new record command straight after opening the form.

You should also be asking the user if they want to proceed BEFORE you open the form (LAE).

This is how I would have approached this

Code:
Dim StrCompany as String
Dim StrStatus AS String
Dim StrEngineer As String
Dim Rst As DAO.Recordset

If MsgBox("Do you want to add a new call log?",vbYesNo,vbQuestion,"Call Logging") = vbYes Then
   StrCompany = Me.Company
   StrStatus = Me.Status
   StrEngineer = Me.Engineer

   Set Rst = CurrentDb.OpenRecordSet("Calls")

   Rst.AddNew
   Rst("Company") = StrCompany      
   Rst("Status") = StrStatus
   Rst("Engineer") = StrEngineer
   Rst.Update
   Rst.Close
   Set Rst = Nothing

   DoCmd.OpenForm "Call Logging"
   DoCmd.GotToRecord,,acLast
End If

This is aircode and as such untested. names are arbitory and used for brevity.

David
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
Thanks, tried that out but still having problems, The message box was right before lol I'm actrually going to be changing what that says to verify the user has entered all the relevant details. Just went about altering my code (drastically :eek:), I'm still getting bugs in it though, The "Job Description" field isn't adding into the table
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
Ok, I've kept working at it but it bugs out when i leave certain fields blank, how do i get it to ignore blank fields???
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
ps. you may ignore post #3, got it working lol
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 02:57
Joined
Mar 10, 2008
Messages
1,746
how come you don't use a bound form? no code required!
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
hi wiklendt,

I'm trying to make it so that it's so easy to use that a 2 month old blind and deaf child will be able to use it lol and there's quite a lot of different functions in the one form so i'm using buttons to deal with all the navigation and commands (makes it look prettier too lol) :D
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 02:57
Joined
Mar 10, 2008
Messages
1,746
hi wiklendt,

I'm trying to make it so that it's so easy to use that a 2 month old blind and deaf child will be able to use it lol and there's quite a lot of different functions in the one form so i'm using buttons to deal with all the navigation and commands (makes it look prettier too lol) :D

the user will not know how the form is powered. all they ever see is that their data goes in.

however, you as the designer will either have: a sh*tload of coding and checking and playing to make it work; or just bind it and have access do the work for you. i prefer the latter.

i've got lots of forms with lots of function and pretty well all of them are bound (except ones like the switchboard etc)

what functions in particular are you using - perhaps we can suggest a design to make it easy for you?
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
actually i am using the swithcboard :) I'm using the buttons and all the code etc because it's code that i'm playing with, not databases and tables per sey. I'm a trainee and just fooling around with code and i'm a bit stuck that's all lol
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 02:57
Joined
Mar 10, 2008
Messages
1,746
actually i am using the swithcboard :) I'm using the buttons and all the code etc because it's code that i'm playing with, not databases and tables per sey. I'm a trainee and just fooling around with code and i'm a bit stuck that's all lol

ok. since you're just playing around it's good you're trying various things. i should warn you though (for future 'real' projects) that you shouldn't use a switchboard for data entry. a switchboard is generally only used to help a user navigate around a complex database, which usually means there are a lot of forms and/or reports to get around. a switchboard traditionally has just buttons on there to open various data entry forms or reports or sub-switchboards or 'nodes', as i like to call them (if you get my meaning).

and also, i have found that the best way to learn access is to actually have some sort of 'real-life' project in mind, otherwise it's just a bit of a mess and nothing works the way it would be setup in 'real-life' (IMHO)...

but good on you for jumping in :) hope yo uhave fun with it all - i certainly do!
 

Brycey

noobish user :P
Local time
Today, 15:57
Joined
Apr 21, 2009
Messages
12
thanks :)

I think you misunderstood, I'm not using the switchboard as a form, it is being used for navigation, i was talking about another form lol. How do you get it to ignore empty fields when inputting info from a form?? it keeps coming up "Invalid use of Null" when i leave certain fields empty eg. Date Closed (I'm making a call logging database ie. you can't have a Date closed if that date hasn't yet passed lol) :D
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 02:57
Joined
Mar 10, 2008
Messages
1,746
it may work to include a null handler

nz()
 

wiklendt

i recommend chocolate
Local time
Tomorrow, 02:57
Joined
Mar 10, 2008
Messages
1,746
thanks :)

I think you misunderstood, I'm not using the switchboard as a form, it is being used for navigation, i was talking about another form lol.

ah. the bit that confused me was when you said "actually i am using the switchboard" in post #9. :p
 

Users who are viewing this thread

Top Bottom