Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables from forms

Status
Not open for further replies.

access345

Programmer
Nov 23, 2005
78
US
I am trying to pass a variable from a form to a query. I am using the following code:

UPDATE TblPAQ3280Process SET TblPAQ3280Process.LaborTI1 = Now(), TblPAQ3280Process.CodeName = "PAQ3280", TblPAQ3280Process.Status = "Incoming Inspection", TblPAQ3280Process.JobNumber = "PAQ" & "Now,mm,dd,yy,"
WHERE (((TblPAQ3280Process.SerialNumber)="& [Forms]![frmInitialInspection]![txtSerialNumber] &"));

I am currently getting a data mismatch error. I tried experimaenting with changing the quote marks around
)="& [Forms]![frmInitialInspection]![txtSerialNumber] &"));

I either get a string error or a data mismatch error.
Any help would be appreciated
 
Are you attempting to run this query using the runSQL method?

A wise man once said
"The only thing normal about database guys is their tables".
 
No, I am running this query from a form. I have the query embedded in a control button within the form.

This is the code:
Private Sub btnIITimeIn_Click()
On Error GoTo Err_btnIITimeIn_Click

Dim stDocName As String


stDocName = "qryInitialInspectionTI"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_btnIITimeIn_Click:
Exit Sub

Err_btnIITimeIn_Click:
MsgBox Err.Description
Resume Exit_btnIITimeIn_Click

End Sub
 
If SerialNumber is a number field in the table, you need to remove the quotes all together:

WHERE (((TblPAQ3280Process.SerialNumber)=& [Forms]![frmInitialInspection]![txtSerialNumber] &));


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
When I tried your code I got a Syntax error (missing operator) in query expression.

So I tried adding quote marks:
WHERE (((TblPAQ3280Process.SerialNumber)="&[Forms]![frmInitialInspection]![txtSerialNumber]&"));

Doing this I got a data mismatch error.
 
Your right I did have to fix that. But It still did not fix my problem. This is my current code.

UPDATE TblPAQ3280Process SET TblPAQ3280Process.LaborTI1 = Now(), TblPAQ3280Process.CodeName = "PAQ3280", TblPAQ3280Process.Status = "Incoming Inspection", TblPAQ3280Process.JobNumber = "PAQ" & Format(Date(),"mmddyyyy")
WHERE (((TblPAQ3280Process.SerialNumber)=[Forms]![frmInitialInspection]![txtSerialNumber]));


Now I get a write conflict It asks me to save my record I click yes but it does not save my record.

on my text box txtserialnumber I have the following code:

Private Sub txtSerialNumber_Exit(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top